:root {
  --bg: #f6f7f5;
  --surface: #ffffff;
  --text: #1e2622;
  --muted: #5c6862;
  --border: #dde3df;
  --green: #2f6b4f;
  --green-dark: #24543e;
  --green-soft: #e8f1ec;
  --amber: #8a5a00;
  --amber-soft: #fdf3dc;
  --red: #a3342b;
  --red-soft: #fbe9e7;
  --blue: #2c5a8a;
  --blue-soft: #e7eff8;
  --grey-soft: #eef0ee;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(20, 40, 30, .06), 0 2px 8px rgba(20, 40, 30, .04);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  color: var(--text);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); }
a { color: var(--green-dark); }
h1 { font-size: 1.5rem; margin: 0 0 .25rem; line-height: 1.25; }
h2 { font-size: 1.15rem; margin: 0 0 .75rem; }
h3 { font-size: 1rem; margin: 0 0 .5rem; }
p { margin: .25rem 0 .75rem; }
.loading { padding: 2rem; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.hidden { display: none !important; }
.mono { font-family: ui-monospace, Consolas, monospace; font-size: .8rem; word-break: break-all; }
.pre { white-space: pre-wrap; }

/* ------------------------------------------------------------ en-tête */
.topbar { background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 10; }
.topbar-inner { max-width: 1180px; margin: 0 auto; padding: .6rem 1rem; display: flex; gap: 1rem; align-items: center; flex-wrap: wrap; }
.brand { font-weight: 700; color: var(--green-dark); text-decoration: none; display: flex; flex-direction: column; line-height: 1.2; }
.brand small { font-weight: 400; color: var(--muted); font-size: .75rem; }
.nav { display: flex; gap: .25rem; flex-wrap: wrap; flex: 1; }
.nav a { text-decoration: none; color: var(--text); padding: .45rem .75rem; border-radius: 8px; font-weight: 500; }
.nav a:hover { background: var(--grey-soft); }
.nav a.active { background: var(--green-soft); color: var(--green-dark); }
.count { display: inline-block; min-width: 1.4em; padding: 0 .35em; border-radius: 99px; background: var(--green); color: #fff; font-size: .75rem; text-align: center; margin-left: .3rem; }
.top-actions { display: flex; gap: .5rem; align-items: center; }
.user-link { color: var(--muted); text-decoration: none; font-size: .9rem; }

main { max-width: 1180px; margin: 0 auto; padding: 1.25rem 1rem 4rem; }
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.page-head .sub { color: var(--muted); margin: 0; }

/* ------------------------------------------------------------ boutons */
button, .btn {
  font: inherit; cursor: pointer; border-radius: 8px; border: 1px solid var(--border); background: var(--surface);
  color: var(--text); padding: .5rem .9rem; font-weight: 500; text-decoration: none; display: inline-flex; align-items: center; gap: .35rem;
  min-height: 40px;
}
button:hover, .btn:hover { border-color: #b9c4bd; background: #fafbfa; }
button:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--green); color: #fff; border-color: var(--green); }
.btn-primary:hover { background: var(--green-dark); border-color: var(--green-dark); }
.btn-danger { color: var(--red); }
.btn-link { border: none; background: none; color: var(--green-dark); padding: .25rem .4rem; min-height: auto; text-decoration: underline; }
.btn-small { padding: .25rem .6rem; font-size: .875rem; min-height: 32px; }
.btn-row { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
:focus-visible { outline: 3px solid #7fb59a; outline-offset: 2px; }

/* ------------------------------------------------------------ cartes */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.1rem; box-shadow: var(--shadow); margin-bottom: 1rem; }
.card.flat { box-shadow: none; }
.section { margin-bottom: 1.5rem; }
.section-title { display: flex; justify-content: space-between; align-items: center; gap: .5rem; margin-bottom: .5rem; flex-wrap: wrap; }
.section-title h2 { margin: 0; }
.grid-2 { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 1.25rem; }
@media (max-width: 900px) { .grid-2 { grid-template-columns: 1fr; } }
.empty { color: var(--muted); padding: .75rem 0; font-style: italic; }

.list-row { display: flex; gap: .75rem; justify-content: space-between; align-items: flex-start; padding: .8rem 0; border-bottom: 1px solid var(--border); }
.list-row:last-child { border-bottom: none; }
.list-row .main { flex: 1; min-width: 0; }
.list-row .title { font-weight: 600; text-decoration: none; color: var(--text); }
.list-row a.title:hover { text-decoration: underline; }
.meta { color: var(--muted); font-size: .875rem; display: flex; flex-wrap: wrap; gap: .25rem .9rem; margin-top: .2rem; }
.meta b { color: var(--text); font-weight: 600; }

/* ------------------------------------------------------------ badges */
.badge { display: inline-flex; align-items: center; gap: .3rem; border-radius: 99px; padding: .1rem .6rem; font-size: .8rem; font-weight: 600; border: 1px solid transparent; white-space: nowrap; }
.b-green { background: var(--green-soft); color: var(--green-dark); border-color: #cfe2d7; }
.b-amber { background: var(--amber-soft); color: var(--amber); border-color: #f1ddb0; }
.b-red { background: var(--red-soft); color: var(--red); border-color: #f2cbc6; }
.b-blue { background: var(--blue-soft); color: var(--blue); border-color: #cddcee; }
.b-grey { background: var(--grey-soft); color: var(--muted); border-color: var(--border); }
.kind { font-size: .75rem; text-transform: uppercase; letter-spacing: .03em; font-weight: 700; color: var(--muted); }
.kind-decision { color: var(--green-dark); }
.kind-action { color: var(--blue); }
.kind-question { color: var(--amber); }
.ref { font-family: ui-monospace, Consolas, monospace; font-size: .85rem; color: var(--muted); }

/* ------------------------------------------------------------ entrées */
.entry { border-left: 3px solid var(--border); padding: .5rem 0 .6rem .8rem; margin: .5rem 0; }
.entry.k-decision { border-left-color: var(--green); }
.entry.k-action { border-left-color: var(--blue); }
.entry.k-question { border-left-color: #d6a23a; }
.entry.k-proposition { border-left-color: #8fb3a0; }
.entry-text { margin: .15rem 0 .25rem; white-space: pre-wrap; }
.entry-head { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.evo-link { font-size: .85rem; color: var(--muted); }

/* ------------------------------------------------------------ formulaires */
label { display: block; font-weight: 600; font-size: .9rem; margin-bottom: .25rem; }
.hint { font-weight: 400; color: var(--muted); font-size: .825rem; }
input[type=text], input[type=password], input[type=date], input[type=search], select, textarea {
  font: inherit; width: 100%; padding: .5rem .65rem; border: 1px solid #c9d2cc; border-radius: 8px; background: #fff; color: var(--text); min-height: 40px;
}
textarea { min-height: 80px; resize: vertical; }
.field { margin-bottom: .85rem; }
.fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: .75rem 1rem; }
.filters { display: flex; flex-wrap: wrap; gap: .6rem; align-items: flex-end; margin-bottom: 1rem; }
.filters .field { margin: 0; min-width: 150px; flex: 1 1 150px; }
.filters .field.grow { flex: 3 1 240px; }
.check { display: inline-flex; align-items: center; gap: .4rem; font-weight: 500; margin-right: .8rem; cursor: pointer; }
.check input { width: 18px; height: 18px; }
.seg { display: inline-flex; border: 1px solid #c9d2cc; border-radius: 8px; overflow: hidden; flex-wrap: wrap; }
.seg button { border: none; border-radius: 0; border-right: 1px solid #c9d2cc; min-height: 38px; }
.seg button:last-child { border-right: none; }
.seg button[aria-pressed=true] { background: var(--green); color: #fff; }

.persons { display: flex; flex-wrap: wrap; gap: .35rem; align-items: center; }
.chip { border: 1px solid #c9d2cc; border-radius: 99px; padding: .2rem .7rem; background: #fff; font-size: .875rem; min-height: 32px; }
.chip[aria-pressed=true] { background: var(--green-soft); border-color: var(--green); color: var(--green-dark); font-weight: 600; }
.chip[aria-pressed=true]::before { content: "✓ "; }
.chip-free { display: inline-flex; align-items: center; gap: .25rem; background: var(--grey-soft); border-radius: 99px; padding: .15rem .3rem .15rem .7rem; font-size: .875rem; }
.chip-free button { min-height: 24px; padding: 0 .4rem; border: none; background: none; }
.persons input[type=text] { width: 170px; min-height: 32px; padding: .2rem .5rem; font-size: .875rem; }

/* ------------------------------------------------------------ bannières */
.banner { border-radius: var(--radius); padding: .8rem 1rem; margin-bottom: 1rem; border: 1px solid; display: flex; gap: .75rem; align-items: flex-start; flex-wrap: wrap; justify-content: space-between; }
.banner.info { background: var(--blue-soft); border-color: #cddcee; }
.banner.ok { background: var(--green-soft); border-color: #cfe2d7; }
.banner.warn { background: var(--amber-soft); border-color: #f1ddb0; }
.banner.err { background: var(--red-soft); border-color: #f2cbc6; }

/* ------------------------------------------------------------ éditeur CR */
.subject-block { border: 1px solid var(--border); border-radius: var(--radius); padding: .9rem 1rem; margin-bottom: 1rem; background: #fcfdfc; }
.subject-block > header { display: flex; justify-content: space-between; gap: .5rem; align-items: baseline; flex-wrap: wrap; margin-bottom: .5rem; }
.edit-entry { background: #fff; border: 1px solid var(--border); border-radius: 8px; padding: .75rem; margin-bottom: .6rem; }
.edit-entry .row { display: flex; gap: .6rem; flex-wrap: wrap; align-items: flex-end; }
.edit-entry .row > * { flex: 1 1 180px; }
.save-state { font-size: .825rem; color: var(--muted); }
.save-state.err { color: var(--red); font-weight: 600; }
.kind-picker { display: flex; flex-wrap: wrap; gap: .35rem; }
.sticky-submit { position: sticky; bottom: 0; background: var(--surface); border-top: 1px solid var(--border); padding: .75rem 1rem; margin: 0 -1.1rem -1rem; border-radius: 0 0 var(--radius) var(--radius); }

/* ------------------------------------------------------------ versions */
.versions { display: flex; gap: .4rem; flex-wrap: wrap; margin: .5rem 0 1rem; }
.versions a { text-decoration: none; border: 1px solid var(--border); border-radius: 8px; padding: .3rem .7rem; color: var(--text); background: #fff; font-size: .9rem; }
.versions a.current { border-color: var(--green); box-shadow: 0 0 0 2px var(--green-soft); font-weight: 600; }
table { border-collapse: collapse; width: 100%; }
th, td { text-align: left; padding: .5rem .4rem; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: .85rem; color: var(--muted); font-weight: 600; }
.diff-before { background: var(--red-soft); text-decoration: line-through; padding: 0 .2rem; }
.diff-after { background: var(--green-soft); padding: 0 .2rem; }

/* ------------------------------------------------------------ historique */
details.history > summary { cursor: pointer; font-weight: 600; padding: .4rem 0; }
.timeline { list-style: none; padding: 0; margin: .5rem 0 0; }
.timeline li { padding: .55rem 0 .55rem 1rem; border-left: 2px solid var(--border); position: relative; }
.timeline li::before { content: ""; position: absolute; left: -6px; top: .95rem; width: 10px; height: 10px; border-radius: 50%; background: var(--surface); border: 2px solid var(--green); }
.timeline .when { font-size: .8rem; color: var(--muted); }

/* ------------------------------------------------------------ dialogues */
dialog { border: none; border-radius: 12px; padding: 0; width: min(640px, calc(100vw - 2rem)); max-height: calc(100vh - 2rem); box-shadow: 0 10px 40px rgba(0,0,0,.2); }
dialog::backdrop { background: rgba(20, 30, 25, .4); }
dialog .dlg-body { padding: 1.25rem 1.25rem .5rem; overflow-y: auto; max-height: calc(100vh - 8rem); }
dialog .dlg-foot { padding: .75rem 1.25rem 1.25rem; display: flex; gap: .5rem; justify-content: flex-end; flex-wrap: wrap; }
.error-text { color: var(--red); font-weight: 600; margin: .5rem 0; }

#toasts { position: fixed; bottom: 1rem; left: 50%; transform: translateX(-50%); z-index: 100; display: flex; flex-direction: column; gap: .5rem; width: min(520px, calc(100vw - 2rem)); }
.toast { background: #1f2d26; color: #fff; padding: .7rem 1rem; border-radius: 8px; box-shadow: 0 4px 16px rgba(0,0,0,.2); }
.toast.err { background: var(--red); }

/* ------------------------------------------------------------ connexion */
.login { max-width: 400px; margin: 10vh auto; }
.login h1 { color: var(--green-dark); }

@media (max-width: 640px) {
  html { font-size: 15px; }
  .topbar { position: static; }
  .topbar-inner { gap: .5rem; }
  .nav { order: 3; width: 100%; flex: 1 1 100%; }
  .nav a { padding: .4rem .55rem; font-size: .95rem; }
  .list-row { flex-direction: column; }
  main { padding: 1rem .75rem 4rem; }
  .card { padding: .85rem; }
  .sticky-submit { margin: 0 -.85rem -.85rem; }
}
@media print {
  .topbar, .no-print, #toasts { display: none !important; }
  body { background: #fff; }
  .card { box-shadow: none; border: none; }
}
