:root {
  --bg: #f5f3ef;
  --surface: #ffffff;
  --ink: #1f2328;
  --muted: #6b6f76;
  --line: #e4e0d8;
  --accent: #2f5d50;
  --accent-ink: #ffffff;
  --pos: #2e7d4f;
  --neg: #b4443a;
  --debt: #8a6d3b;
  --unk: #a9a59c;
  --warn-bg: #fff4dc;
  --warn-ink: #7a5300;
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15171a;
    --surface: #1e2125;
    --ink: #e8e6e1;
    --muted: #9a9ea5;
    --line: #2f3338;
    --accent: #6fb39d;
    --accent-ink: #0f1513;
    --pos: #6cc28f;
    --neg: #e3796e;
    --debt: #c9a86a;
    --unk: #6d6a64;
    --warn-bg: #3a3020;
    --warn-ink: #f0cf8a;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); text-decoration-thickness: 1px; text-underline-offset: 2px; }
h1 { font-size: 1.6rem; margin: 0 0 .25rem; line-height: 1.2; }
h2 { font-size: 1.15rem; margin: 0 0 .75rem; }
h3 { font-size: .95rem; margin: 1.25rem 0 .5rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
h2 a { color: inherit; text-decoration: none; }
code { font-size: .9em; background: var(--bg); padding: .1em .35em; border-radius: 4px; }
small { font-size: .82em; }
.muted { color: var(--muted); }
.pos { color: var(--pos); }
.neg { color: var(--neg); }
.r { text-align: right; }

/* En-tête */
.top {
  display: flex; align-items: center; gap: 1.5rem;
  padding: .6rem 1.25rem; background: var(--surface); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 10;
}
.brand { font-weight: 700; color: var(--ink); text-decoration: none; display: flex; align-items: center; gap: .5rem; white-space: nowrap; }
.brand-mark { width: 22px; height: 22px; border-radius: 6px; background: var(--accent); display: inline-block; }
.nav { display: flex; gap: .25rem; flex: 1; overflow-x: auto; }
.nav a { padding: .4rem .7rem; border-radius: 8px; color: var(--muted); text-decoration: none; white-space: nowrap; }
.nav a:hover { color: var(--ink); background: var(--bg); }
.nav a[aria-current] { color: var(--ink); background: var(--bg); font-weight: 600; }
.logout { display: flex; align-items: center; gap: .5rem; margin: 0; }
.who { color: var(--muted); }

.page { max-width: 1120px; margin: 0 auto; padding: 1.5rem 1.25rem 4rem; }
.page.narrow { max-width: 440px; padding-top: 12vh; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 1rem; margin-bottom: 1rem; flex-wrap: wrap; }
.crumb { margin: 0 0 .25rem; font-size: .9rem; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.25rem; margin-bottom: 1.25rem; }
.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; flex-wrap: wrap; }
.card-head h2 { margin-bottom: .25rem; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 1.25rem; }
.grid2 > .card { margin-bottom: 0; }
.grid2 + .card, .grid2 { margin-bottom: 1.25rem; }
.list { display: grid; gap: .6rem; margin-bottom: 1.25rem; }
.row-link { display: flex; gap: .75rem; align-items: baseline; flex-wrap: wrap; text-decoration: none; color: var(--ink); margin: 0; }
.row-link:hover { border-color: var(--accent); }

/* Indicateurs */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: .75rem; margin: 1rem 0 1.25rem; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: .8rem 1rem; display: flex; flex-direction: column; gap: .15rem; }
.card .kpi { background: var(--bg); border-color: transparent; }
.kpi span { color: var(--muted); font-size: .85rem; }
.kpi strong { font-size: 1.35rem; font-variant-numeric: tabular-nums; line-height: 1.2; }
.kpi small { color: var(--muted); }
progress, meter { width: 100%; height: 6px; accent-color: var(--accent); }
td meter { width: 70px; vertical-align: middle; }

.tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--line); margin-bottom: 1.25rem; overflow-x: auto; }
.tabs a { padding: .55rem .85rem; color: var(--muted); text-decoration: none; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs a[aria-current] { color: var(--ink); border-color: var(--accent); font-weight: 600; }

.tag { display: inline-block; font-size: .75rem; font-weight: 600; padding: .1rem .5rem; border-radius: 99px; background: var(--bg); color: var(--muted); vertical-align: middle; }
.tag.warn, .tag-compromis { background: var(--warn-bg); color: var(--warn-ink); }
.tag-acquis { background: color-mix(in srgb, var(--pos) 18%, transparent); color: var(--pos); }
.auto { font-size: .7rem; color: var(--muted); border: 1px solid var(--line); border-radius: 4px; padding: 0 .3rem; }

.flash { background: color-mix(in srgb, var(--accent) 14%, var(--surface)); border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent); padding: .7rem 1rem; border-radius: var(--radius); margin-bottom: 1.25rem; }
.error { color: var(--neg); }
.hint { background: var(--warn-bg); color: var(--warn-ink); padding: .7rem 1rem; border-radius: var(--radius); }
.hint a { color: inherit; font-weight: 600; }
.alerts { list-style: none; padding: 0; margin: 1rem 0; display: flex; gap: .5rem; flex-wrap: wrap; }
.alerts a { display: block; background: var(--warn-bg); color: var(--warn-ink); padding: .4rem .8rem; border-radius: 99px; text-decoration: none; font-weight: 600; font-size: .9rem; }
ul.plain { list-style: none; padding: 0; margin: 0; }
ul.plain li { padding: .35rem 0; border-bottom: 1px solid var(--line); }
ul.plain li:last-child { border-bottom: 0; }

/* Formulaires */
input, select, textarea, button { font: inherit; color: inherit; }
input:not([type=checkbox]):not([type=file]), select, textarea {
  width: 100%; padding: .5rem .65rem; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); min-height: 2.4rem;
}
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
label { display: flex; flex-direction: column; gap: .25rem; font-size: .88rem; color: var(--muted); }
label > input, label > select, label > textarea { color: var(--ink); font-size: 1rem; }
.stack { display: grid; gap: .9rem; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: .9rem 1rem; align-items: end; }
.form-grid.compact { gap: .6rem .8rem; margin: .75rem 0; }
.form-grid .full, .form-grid h3 { grid-column: 1 / -1; }
.form-grid h3 { margin: .75rem 0 0; }
.inline { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.inline > input, .inline > select { width: auto; flex: 1 1 160px; }
.inline.tight { flex-wrap: nowrap; }
.inline.tight select { min-width: 9rem; }
.check-inline { flex-direction: row; align-items: center; gap: .4rem; color: var(--ink); }
.check-inline .short, input.short { width: 14rem; flex: 0 1 14rem; }
.filters { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; margin-bottom: 1rem; }
.filters > select, .filters > input { width: auto; flex: 1 1 150px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: .4rem; padding: .5rem 1rem; min-height: 2.4rem; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); text-decoration: none; cursor: pointer; font-weight: 600; white-space: nowrap; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.link { background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer; text-decoration: underline; text-underline-offset: 2px; }
.link.danger { color: var(--neg); }
details > summary { cursor: pointer; color: var(--accent); font-weight: 600; margin-top: .75rem; }
details[open] > summary { margin-bottom: .25rem; }
.auth h1 { margin-bottom: .25rem; }

/* Tableaux */
.table-wrap { overflow-x: auto; margin: 0 -.25rem; padding: 0 .25rem; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: .5rem .6rem; border-bottom: 1px solid var(--line); vertical-align: top; }
thead th { font-size: .8rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; white-space: nowrap; }
tbody th { font-weight: 500; }
table.num td { text-align: right; white-space: nowrap; }
tr.sub th, tr.sub td { font-weight: 700; border-top: 2px solid var(--line); }
tr.cancelled td { color: var(--muted); text-decoration: line-through; }
tr.cancelled td:last-child { text-decoration: none; }
tr.todo td:nth-child(4)::after { content: "à compléter"; font-size: .75rem; color: var(--warn-ink); background: var(--warn-bg); padding: 0 .35rem; border-radius: 4px; }
.row-edit summary { margin: 0; font-weight: 500; }
.row-edit[open] { min-width: 320px; }

/* Opérations */
.ops { display: grid; gap: .4rem; margin-bottom: 1.25rem; }
.op { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 0 .9rem; }
.op.unclassified { border-left: 3px solid var(--warn-ink); }
.op > summary { list-style: none; display: grid; grid-template-columns: 6.5rem 1fr minmax(8rem, auto) 7.5rem; gap: .75rem; align-items: center; padding: .6rem 0; margin: 0; color: var(--ink); font-weight: 400; }
.op > summary::-webkit-details-marker { display: none; }
.op-date { color: var(--muted); font-size: .9rem; font-variant-numeric: tabular-nums; }
.op-label { overflow: hidden; }
.op-label small { display: block; color: var(--muted); }
.op-cat { font-size: .9rem; }
.op-amount { text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }
.op[open] { padding-bottom: .75rem; }

/* Checklists */
.checklist { list-style: none; padding: 0; margin: .75rem 0 0; }
.checklist .section { font-weight: 700; margin: 1.1rem 0 .3rem; }
.checklist .item { display: flex; justify-content: space-between; gap: 1rem; align-items: baseline; border-bottom: 1px solid var(--line); }
.checklist .item form { flex: 1; }
.checklist .depth-1 { padding-left: 1.75rem; }
.check { display: flex; gap: .65rem; align-items: flex-start; background: none; border: 0; padding: .45rem 0; text-align: left; cursor: pointer; width: 100%; }
.check .box { flex: 0 0 18px; height: 18px; margin-top: .15rem; border: 2px solid var(--muted); border-radius: 5px; position: relative; }
.done .check .box { background: var(--accent); border-color: var(--accent); }
.done .check .box::after { content: ""; position: absolute; left: 4px; top: 0; width: 5px; height: 10px; border: solid var(--accent-ink); border-width: 0 2px 2px 0; transform: rotate(45deg); }
.done .check .label { color: var(--muted); text-decoration: line-through; }
.checklist .meta { color: var(--muted); font-size: .8rem; white-space: nowrap; }
.hide-done .item.done { display: none; }
.toggle-done { flex-direction: row; gap: .4rem; align-items: center; margin-top: .5rem; }
.doc { display: flex; gap: 1rem; align-items: baseline; justify-content: space-between; padding: .35rem 0; border-bottom: 1px solid var(--line); }

/* Graphiques */
.chart { width: 100%; height: auto; display: block; margin: .5rem 0; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .grid.zero { stroke: var(--muted); }
.chart .axis { fill: var(--muted); font-size: 11px; }
.s-pos { fill: var(--pos); background: var(--pos); }
.s-neg { fill: var(--neg); background: var(--neg); }
.s-debt { fill: var(--debt); background: var(--debt); }
.s-unk { fill: var(--unk); background: var(--unk); }
.s-line { fill: none; stroke: var(--ink); stroke-width: 2; background: var(--ink); }
.s-dot { fill: var(--surface); stroke: var(--ink); stroke-width: 2; }
.legend { color: var(--muted); font-size: .85rem; display: flex; gap: .4rem 1rem; flex-wrap: wrap; align-items: center; }
.sw { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: .1rem; }
.sw.s-line { height: 2px; width: 14px; }

@media (max-width: 720px) {
  body { font-size: 15px; }
  .top { flex-wrap: wrap; gap: .5rem; padding: .5rem 1rem; }
  .nav { order: 3; width: 100%; flex: 1 1 100%; }
  .logout { margin-left: auto; }
  .who { display: none; }
  .page { padding: 1rem 1rem 3rem; }
  .card { padding: 1rem; }
  .op > summary { grid-template-columns: 1fr auto; grid-template-areas: "label amount" "date cat"; gap: .1rem .75rem; }
  .op-label { grid-area: label; }
  .op-amount { grid-area: amount; }
  .op-date { grid-area: date; }
  .op-cat { grid-area: cat; text-align: right; }
  .grid2 { grid-template-columns: 1fr; }
  .kpis { grid-template-columns: 1fr 1fr; gap: .5rem; }
  .kpi strong { font-size: 1.15rem; }
  .checklist .item { flex-direction: column; gap: 0; }
}
