:root {
  --bg: #f5f2ec;
  --card: #ffffff;
  --ink: #1d2622;
  --muted: #6b746f;
  --line: #e6e1d8;
  --brand: #1f3b33;
  --brand-2: #2f5a4d;
  --accent: #c8873a;
  --pos: #2e7d5b;
  --neg: #b4443a;
  --in: #3f8f74;
  --out: #d39a55;
  --soft: #eef2ef;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(29,38,34,.05), 0 4px 16px rgba(29,38,34,.05);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #131816; --card: #1b2220; --ink: #e8ece9; --muted: #98a39d; --line: #2a3330;
    --brand: #8fc7b0; --brand-2: #6fae96; --soft: #22302b; --in: #5fb394; --out: #d9a868;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font: 15px/1.5 var(--font); -webkit-font-smoothing: antialiased; }
a { color: var(--brand-2); }
h1, h2 { margin: 0; letter-spacing: -.01em; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.05rem; font-weight: 650; }
small, .small { font-size: .82rem; }
.muted { color: var(--muted); }
.center { text-align: center; }

/* ---- Barre du haut ---- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 24px;
  padding: 10px 24px; background: var(--brand); color: #fff;
}
@media (prefers-color-scheme: dark) { .topbar { background: #0f1412; border-bottom: 1px solid var(--line); } }
.brand { color: inherit; text-decoration: none; font-weight: 700; font-size: 1.05rem; white-space: nowrap; }
.brand-mark { color: var(--accent); }
.brand.big { font-size: 1.5rem; text-align: center; margin-bottom: 18px; color: var(--ink); }
.mainnav { display: flex; gap: 4px; flex: 1; }
.mainnav a {
  color: rgba(255,255,255,.75); text-decoration: none; padding: 7px 12px; border-radius: 9px;
  display: flex; align-items: center; gap: 6px; font-size: .92rem;
}
.mainnav a:hover { color: #fff; background: rgba(255,255,255,.08); }
.mainnav a.on { color: #fff; background: rgba(255,255,255,.14); }
.mainnav .ico { opacity: .8; }
.who { display: flex; align-items: center; gap: 12px; font-size: .88rem; color: rgba(255,255,255,.85); }
.who form { margin: 0; }
.linkbtn { background: none; border: 0; color: inherit; text-decoration: underline; cursor: pointer; font: inherit; padding: 0; opacity: .8; }

.wrap { max-width: 1120px; margin: 0 auto; padding: 24px 20px 40px; }

/* ---- Cartes ---- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow); margin-bottom: 18px; }
.card h2 { margin-bottom: 12px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.card-head h2 { margin: 0; }
.card.narrow { max-width: 420px; margin: 40px auto; }
.card.narrow-ish { max-width: 560px; margin: 0 auto; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.grid2 > .card { margin-bottom: 0; }
.grid2 { margin-bottom: 18px; }
.pagehead { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.pill { background: var(--card); border: 1px solid var(--line); border-radius: 999px; padding: 6px 14px; font-size: .9rem; }
.total { font-weight: 700; font-variant-numeric: tabular-nums; }

/* ---- Navigation de mois ---- */
.monthnav { display: flex; align-items: center; gap: 10px; margin-bottom: 18px; }
.monthnav h1 { min-width: 190px; text-align: center; }

/* ---- KPI ---- */
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 18px; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; display: flex; flex-direction: column; gap: 2px; box-shadow: var(--shadow); }
.kpi-label { font-size: .82rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.kpi-value { font-size: 1.45rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.kpi-sub { font-size: .82rem; color: var(--muted); }
.kpi-sub.warn { color: var(--accent); }
.kpi.hero { background: var(--brand); border-color: var(--brand); color: #fff; }
.kpi.hero .kpi-label, .kpi.hero .kpi-sub { color: rgba(255,255,255,.75); }
.kpi.hero.neg { background: var(--neg); border-color: var(--neg); }
@media (prefers-color-scheme: dark) { .kpi.hero { background: #1f3b33; border-color: #2f5a4d; } }

/* ---- Formulaires ---- */
.form { display: flex; flex-direction: column; gap: 12px; }
.form label { display: flex; flex-direction: column; gap: 4px; font-size: .82rem; color: var(--muted); font-weight: 500; }
.form input, .form select {
  font: inherit; font-size: 15px; color: var(--ink); background: var(--bg);
  border: 1px solid var(--line); border-radius: 10px; padding: 9px 11px; min-height: 40px; width: 100%;
}
.form input:focus, .form select:focus { outline: 2px solid var(--brand-2); outline-offset: -1px; background: var(--card); }
.form input[type=file] { padding: 7px; }
.form label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--ink); font-size: .92rem; }
.form label.check input { width: auto; min-height: 0; }
.inline-form { flex-direction: row; flex-wrap: wrap; align-items: flex-end; }
.inline-form label { flex: 1 1 130px; }
.inline-form label.grow { flex: 2 1 200px; }
.grid-form { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.grid-form .span2 { grid-column: span 2; }
.grid-form .span-all { grid-column: 1 / -1; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.row-actions { display: flex; gap: 10px; flex-wrap: wrap; }
fieldset.box { border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; margin: 0; display: flex; flex-direction: column; gap: 8px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: inherit; font-weight: 600; font-size: .92rem; text-decoration: none; cursor: pointer;
  padding: 9px 16px; min-height: 40px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--card); color: var(--ink);
}
.btn:hover { border-color: var(--brand-2); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-2); }
@media (prefers-color-scheme: dark) { .btn.primary { background: #2f5a4d; border-color: #2f5a4d; } }
.btn.ghost { background: transparent; }
.btn.small { padding: 5px 11px; min-height: 32px; font-size: .84rem; }
.btn.big { min-height: 50px; font-size: 1rem; }
.btn:disabled { opacity: .6; cursor: wait; }

.flash { padding: 10px 14px; border-radius: 10px; margin-bottom: 14px; font-size: .92rem; background: var(--soft); border: 1px solid var(--line); }
.flash.ok { border-color: #b9dccb; background: #ecf6f0; color: #1e5a40; }
.flash.err { border-color: #e8bdb7; background: #fbefed; color: #8a2f26; }
.flash.warn { border-color: #ebd3ae; background: #fbf4e8; color: #7a5218; }
@media (prefers-color-scheme: dark) {
  .flash.ok { background: #183028; color: #a9dcc4; border-color: #24453a; }
  .flash.err { background: #3a1f1c; color: #f0b8b0; border-color: #5a2d28; }
  .flash.warn { background: #3a2f1c; color: #ecd2a5; border-color: #5a4728; }
}

/* ---- Tableaux ---- */
.tbl { width: 100%; border-collapse: collapse; font-size: .92rem; }
.tbl th { text-align: left; font-size: .76rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; padding: 6px 8px; border-bottom: 1px solid var(--line); }
.tbl td { padding: 9px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; font-weight: 600; }
.tbl .d { color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.tbl tr.dim td { opacity: .5; }
.actions { white-space: nowrap; text-align: right; width: 1%; }
.actions form { display: inline; margin: 0; }
.iconbtn { display: inline-flex; align-items: center; justify-content: center; width: 30px; height: 30px; border-radius: 8px; border: 1px solid transparent; background: none; color: var(--muted); cursor: pointer; text-decoration: none; font-size: .95rem; }
.iconbtn:hover { border-color: var(--line); color: var(--ink); }
.iconbtn.danger:hover { color: var(--neg); }
.tag { display: inline-block; font-size: .74rem; padding: 2px 8px; border-radius: 999px; background: var(--soft); color: var(--muted); white-space: nowrap; }
.tag.soft { background: transparent; border: 1px solid var(--line); }
.att { text-decoration: none; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.chip { font-size: .8rem; padding: 4px 11px; border-radius: 999px; border: 1px solid var(--line); text-decoration: none; color: var(--muted); }
.chip.on { background: var(--brand); border-color: var(--brand); color: #fff; }

/* ---- Barres par catégorie ---- */
.bars { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 9px; }
.bars li { display: grid; grid-template-columns: 96px 1fr 80px; align-items: center; gap: 10px; font-size: .88rem; }
.bar-track { height: 10px; background: var(--soft); border-radius: 999px; overflow: hidden; }
.bar-fill { display: block; height: 100%; background: var(--out); border-radius: 999px; }
.bar-val { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }

/* ---- Checklist charges ---- */
.checklist { list-style: none; margin: 0 0 8px; padding: 0; }
.checklist li { display: flex; align-items: center; gap: 10px; padding: 7px 0; border-bottom: 1px solid var(--line); }
.checklist li:last-child { border-bottom: 0; }
.checklist form { margin: 0; }
.tick { width: 24px; height: 24px; border-radius: 7px; border: 1.5px solid var(--line); background: var(--card); cursor: pointer; color: #fff; font-size: .8rem; font-weight: 700; padding: 0; }
.tick:hover { border-color: var(--brand-2); }
.checklist li.done .tick { background: var(--pos); border-color: var(--pos); }
.checklist li.done .cl-name { color: var(--muted); text-decoration: line-through; text-decoration-color: var(--line); }
.cl-name { flex: 1; font-size: .92rem; }
.cl-name small { color: var(--muted); margin-left: 6px; }
.cl-amt { font-variant-numeric: tabular-nums; font-weight: 600; font-size: .92rem; }

/* ---- Historique ---- */
.legend { font-size: .78rem; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.sw { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-left: 6px; }
.sw.in { background: var(--in); } .sw.out { background: var(--out); }
.hist { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; height: 170px; align-items: end; }
.hist-col { display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; text-decoration: none; color: var(--muted); border-radius: 8px; padding-top: 4px; }
.hist-col.cur { background: var(--soft); color: var(--ink); font-weight: 600; }
.hist-bars { flex: 1; display: flex; align-items: flex-end; gap: 3px; width: 100%; justify-content: center; }
.hb { width: 34%; max-width: 18px; border-radius: 4px 4px 0 0; min-height: 2px; }
.hb.in { background: var(--in); } .hb.out { background: var(--out); }
.hist-lbl { font-size: .76rem; padding-bottom: 4px; }

/* ---- Scan ---- */
.dropzone {
  position: relative; display: flex !important; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  border: 2px dashed var(--line); border-radius: 16px; padding: 36px 20px; text-align: center; cursor: pointer; background: var(--bg);
}
.dropzone:hover { border-color: var(--brand-2); }
.dropzone input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.dz-ico { font-size: 2.2rem; color: var(--brand-2); line-height: 1; }
.dz-title { font-size: 1rem; font-weight: 650; color: var(--ink); }
.dz-sub { color: var(--muted); }
.dz-name { color: var(--ink); font-size: .85rem; }
#dzPreview { max-width: 100%; max-height: 260px; border-radius: 10px; margin-top: 10px; }
.scan-confirm .preview { padding: 10px; display: flex; align-items: flex-start; justify-content: center; }
.scan-confirm .preview img { max-width: 100%; max-height: 75vh; border-radius: 10px; }
.pdfview { width: 100%; height: 75vh; border: 0; border-radius: 10px; }
.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; background: var(--bg); padding: 4px; border-radius: 12px; border: 1px solid var(--line); }
.seg label { flex-direction: row !important; align-items: center; justify-content: center; gap: 6px !important; padding: 8px; border-radius: 9px; cursor: pointer; color: var(--ink) !important; font-size: .9rem !important; }
.seg input { width: auto !important; min-height: 0 !important; accent-color: var(--brand); }
.seg label:has(input:checked) { background: var(--card); box-shadow: var(--shadow); font-weight: 600; }
[hidden] { display: none !important; }

/* ---- Mobile ---- */
@media (max-width: 900px) {
  .kpis { grid-template-columns: 1fr 1fr; }
  .grid2 { grid-template-columns: 1fr; }
  .grid-form { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 680px) {
  body { padding-bottom: 76px; }
  .topbar { padding: 10px 16px; gap: 12px; }
  .who span { display: none; }
  .mainnav {
    position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
    background: var(--brand); justify-content: space-around; gap: 0;
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  }
  @media (prefers-color-scheme: dark) { .mainnav { background: #0f1412; border-top: 1px solid var(--line); } }
  .mainnav a { flex-direction: column; gap: 1px; padding: 5px 6px; font-size: .68rem; flex: 1; }
  .mainnav .ico { font-size: 1.15rem; }
  .wrap { padding: 16px 14px 32px; }
  .monthnav h1 { min-width: 0; flex: 1; font-size: 1.25rem; }
  .kpi-value { font-size: 1.2rem; }
  .card { padding: 15px 15px; }
  .inline-form label, .inline-form label.grow { flex: 1 1 100%; }
  .inline-form .btn { width: 100%; }
  .grid-form { grid-template-columns: 1fr; }
  .grid-form .span2 { grid-column: auto; }
  .bars li { grid-template-columns: 80px 1fr 70px; }
  .tbl th:nth-child(3), .tbl td:nth-child(3) { display: none; }
}

/* Bandeau quand Christophe consulte l'espace depuis son compte */
.adminbar { background: #c8873a; color: #fff; text-align: center; padding: 7px 16px; font-size: .88rem; font-weight: 600; }
.adminbar a { color: #fff; }

/* ---- Tableau de bord v2 : disponible + ajout en premier ---- */
.top { display: grid; grid-template-columns: minmax(240px, 1fr) 2fr; gap: 14px; margin-bottom: 14px; align-items: stretch; }
.top > .card { margin-bottom: 0; }
.kpi.hero.big { justify-content: center; padding: 20px 22px; }
.kpi.hero.big .kpi-value { font-size: 2.1rem; line-height: 1.15; }
.kpi.hero.big .kpi-sub { line-height: 1.45; }
.kpis.three { grid-template-columns: repeat(3, 1fr); }
.tbl.compact td { padding: 7px 6px; }
.allbar { display: flex; gap: 8px; flex-wrap: wrap; margin: -4px 0 8px; }
.savings .inline-form { margin-bottom: 10px; }
.savings .pill { font-size: .82rem; padding: 4px 11px; }
/* Revenus automatiques */
form.rule { padding: 12px 0; border-top: 1px solid var(--line); }
form.rule:first-of-type { border-top: 0; padding-top: 0; }
form.rule.dim { opacity: .6; }
form.rule .span-row { flex-basis: 100%; margin: 0; }
form.rule label.check { flex: 0 0 auto; align-self: center; padding-top: 18px; }
form.rule .iconbtn { align-self: center; margin-top: 18px; }
.addrule { margin-top: 12px; }
.addrule summary { cursor: pointer; color: var(--brand-2); font-weight: 600; font-size: .92rem; padding: 6px 0; }
.addrule form { margin-top: 10px; }
@media (max-width: 900px) {
  .top { grid-template-columns: 1fr; }
  .kpis.three { grid-template-columns: 1fr 1fr 1fr; }
}
@media (max-width: 680px) {
  .kpis.three { grid-template-columns: 1fr 1fr; }
  .kpis.three .kpi:last-child { grid-column: span 2; }
  .kpi.hero.big .kpi-value { font-size: 1.8rem; }
}

/* Bouton de téléchargement Excel */
.monthnav .xlsbtn { margin-left: auto; }
@media (max-width: 680px) { .monthnav .xlsbtn { font-size: 0; padding: 5px 10px; } .monthnav .xlsbtn::before { content: "⬇ Excel"; font-size: .84rem; } }

/* Nom de la personne connectée (lien vers Accès) */
.who .whoname { color: inherit; text-decoration: none; }
.who .whoname:hover { text-decoration: underline; }
@media (max-width: 680px) { .who .whoname { display: none; } .mainnav a { padding: 5px 2px; font-size: .62rem; } }

/* Tableau de bord v3 */
.kpi.hero.dispo { margin-bottom: 14px; }
.pill.ok { color: var(--pos); border-color: var(--pos); font-size: .8rem; padding: 3px 10px; }
.addcard { margin-bottom: 18px; }
.tbl.mt { margin-top: 12px; }

/* Prévisions : toujours marquées « prévision », en pointillés */
.fc-tag { display: inline-block; font-size: .68rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em;
  padding: 2px 7px; border-radius: 999px; border: 1px dashed currentColor; color: var(--accent); white-space: nowrap; }
.kpi.hero .forecast { margin-top: 14px; padding-top: 12px; border-top: 1px dashed rgba(255,255,255,.3);
  display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; }
.kpi.hero .forecast .fc-tag { color: #f0c48a; }
.kpi.hero .fc-label { font-size: .85rem; color: rgba(255,255,255,.8); }
.kpi.hero .fc-value { font-size: 1.25rem; font-weight: 700; font-style: italic; }
.kpi.hero .fc-detail { flex-basis: 100%; font-size: .78rem; color: rgba(255,255,255,.65); font-style: italic; }
.tbl tr.fc-row td { color: var(--muted); font-style: italic; border-bottom-style: dashed; }
.fc-line { font-size: .84rem; color: var(--muted); font-style: italic; margin: -4px 0 10px; }

/* Épargne v2 */
.save-total { font-size: 1.9rem; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--pos); margin: -4px 0 4px; }
.tbl .num.pos { color: var(--pos); }
.tbl .num.neg { color: var(--neg); }

/* Solde de départ */
.kpi.hero details.opening { margin-top: 10px; font-size: .82rem; color: rgba(255,255,255,.75); }
.kpi.hero details.opening summary { cursor: pointer; }
.kpi.hero details.opening form { margin-top: 8px; }
.kpi.hero details.opening label { color: rgba(255,255,255,.8); }
.kpi.hero details.opening input { background: rgba(255,255,255,.95); }
.kpi.hero details.opening .btn { background: #fff; color: var(--brand); border-color: #fff; }

/* Solde de départ, bien visible */
.opening-card { margin-bottom: 14px; border: 1px dashed var(--accent); }
.opening-card.set { border-style: solid; border-color: var(--line); padding-top: 12px; padding-bottom: 12px; }
.opening-card.set .opening-form { display: none; margin-top: 12px; }
.opening-card.set.open .opening-form { display: flex; }
.opening-line { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; font-size: .92rem; }

/* Revenus : salaire utilisé ce mois-ci en tête */
.tbl.salaries tr.sal-used td { font-weight: 600; background: var(--soft); }
.tbl.salaries tr.sal-used td small { font-weight: 400; }
.tbl.salaries td small { font-size: .76rem; }

/* Versements du dimanche */
.sundays { margin-top: 14px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; }
.sun-head { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; font-size: .9rem; margin-bottom: 4px; }
.sun-head span { font-variant-numeric: tabular-nums; color: var(--muted); }
.tag.ok { background: transparent; color: var(--pos); border: 1px solid var(--pos); }

/* Mode d'emploi */
.guide details > summary { list-style: none; cursor: pointer; display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.guide details > summary::-webkit-details-marker { display: none; }
.guide details > summary h2 { margin: 0; }
.guide details > summary h2::before { content: "▸ "; color: var(--accent); }
.guide details[open] > summary h2::before { content: "▾ "; }
.guide-flow { display: grid; grid-template-columns: 1fr auto 1fr auto 1fr auto 1fr; gap: 8px; align-items: stretch; margin: 18px 0; }
.guide-flow .step { background: var(--soft); border-radius: 12px; padding: 12px; display: flex; flex-direction: column; gap: 4px; font-size: .86rem; }
.guide-flow .step strong { font-size: .95rem; }
.guide-flow .n { width: 22px; height: 22px; border-radius: 50%; background: var(--brand); color: #fff; font-size: .75rem; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; }
.guide-flow .arrow { align-self: center; color: var(--muted); font-size: 1.2rem; }
.guide-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px 22px; }
.guide-grid h3 { font-size: .95rem; margin: 0 0 6px; }
.guide-grid p, .guide-grid ul { font-size: .88rem; line-height: 1.5; margin: 0; color: var(--ink); }
.guide-grid ul { padding-left: 18px; }
.guide-grid li { margin-bottom: 4px; }
.guide-foot { margin-top: 18px; padding-top: 12px; border-top: 1px solid var(--line); }
@media (max-width: 900px) {
  .guide-flow { grid-template-columns: 1fr; }
  .guide-flow .arrow { transform: rotate(90deg); justify-self: center; }
  .guide-grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 680px) { .guide-grid { grid-template-columns: 1fr; } }

/* Mention « payées le 25 » */
.due-note { font-size: .84rem; color: var(--brand-2); background: var(--soft); border-radius: 8px; padding: 6px 10px; margin: -4px 0 12px; }
.due-note.inline { display: inline-block; margin: 0 0 0 10px; font-weight: 500; vertical-align: middle; }
