:root {
  --bg: #f4f5f2;
  --surface: #ffffff;
  --surface-2: #f9faf8;
  --line: #dde2dc;
  --line-strong: #c3cbc4;
  --text: #1b231e;
  --muted: #5b665e;
  --primary: #1f5135;
  --primary-hover: #17402a;
  --primary-soft: #e3eee6;
  --primary-ink: #ffffff;
  --danger: #b0261c;
  --danger-soft: #fbe9e7;
  --warn: #7a4f00;
  --warn-soft: #fff3d6;
  --ok: #1d6b3d;
  --ok-soft: #e1f2e7;
  --info: #1f4f7a;
  --info-soft: #e5eef7;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(20, 30, 24, .06), 0 2px 8px rgba(20, 30, 24, .05);
  --nav-h: 64px;
  --top-h: 56px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", Ubuntu, sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text); font: 16px/1.45 var(--font);
  -webkit-tap-highlight-color: transparent;
}
h1, h2, h3 { line-height: 1.2; margin: 0; }
h1 { font-size: 1.4rem; }
h2 { font-size: 1.12rem; }
h3 { font-size: 1rem; }
a { color: var(--primary); }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }
svg[viewBox="0 0 24 24"] { width: 20px; height: 20px; flex: none; }
.boot { padding: 40vh 0 0; text-align: center; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.neg { color: var(--danger); font-weight: 600; }
.right { text-align: right; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.stack > * + * { margin-top: 12px; }
.grow { flex: 1; min-width: 0; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

.offline {
  position: sticky; top: 0; z-index: 60; background: var(--warn-soft); color: var(--warn);
  padding: 8px 16px; font-size: .9rem; border-bottom: 1px solid #ecd9a6;
}

/* ---------------------------------------------------------------- layout */
.topbar {
  position: sticky; top: 0; z-index: 30; height: var(--top-h); background: var(--primary); color: #fff;
  display: flex; align-items: center; gap: 8px; padding: 0 12px; padding-top: env(safe-area-inset-top);
}
.topbar .brand { font-weight: 700; letter-spacing: .01em; white-space: nowrap; text-decoration: none; color: #fff; }
.project-switch {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: 6px; background: rgba(255,255,255,.12);
  border: 1px solid rgba(255,255,255,.22); color: #fff; border-radius: 10px; padding: 7px 10px;
  cursor: pointer; text-align: left;
}
.project-switch .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.project-switch .lab { font-size: .72rem; opacity: .85; display: block; }
.topbar .icon-btn { color: #fff; }
.layout { display: flex; min-height: calc(100vh - var(--top-h)); }
.sidenav { display: none; }
main.content { flex: 1; min-width: 0; padding: 16px 16px calc(var(--nav-h) + 96px); max-width: 1180px; margin: 0 auto; width: 100%; }
.bottomnav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 30; background: var(--surface);
  border-top: 1px solid var(--line); display: grid; grid-template-columns: repeat(5, 1fr);
  padding-bottom: env(safe-area-inset-bottom); height: calc(var(--nav-h) + env(safe-area-inset-bottom));
}
.bottomnav a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  text-decoration: none; color: var(--muted); font-size: .72rem; font-weight: 600;
}
.bottomnav a svg { width: 24px; height: 24px; }
.bottomnav a[aria-current="page"] { color: var(--primary); }
.bottomnav a[aria-current="page"] svg { stroke-width: 2.4; }
.fab {
  position: fixed; right: 16px; bottom: calc(var(--nav-h) + 16px + env(safe-area-inset-bottom)); z-index: 31;
  height: 56px; border-radius: 28px; border: 0; background: var(--primary); color: #fff; padding: 0 20px 0 16px;
  display: flex; align-items: center; gap: 8px; font-weight: 700; box-shadow: 0 4px 14px rgba(20,60,35,.35); cursor: pointer;
}
.fab svg { width: 24px; height: 24px; }

@media (min-width: 900px) {
  .bottomnav, .fab { display: none; }
  .sidenav {
    display: block; width: 240px; flex: none; background: var(--surface); border-right: 1px solid var(--line);
    padding: 16px 10px; position: sticky; top: var(--top-h); height: calc(100vh - var(--top-h)); overflow: auto;
  }
  .sidenav a {
    display: flex; gap: 10px; align-items: center; padding: 10px 12px; border-radius: 10px; text-decoration: none;
    color: var(--text); font-weight: 500; margin-bottom: 2px;
  }
  .sidenav a svg { width: 20px; height: 20px; color: var(--muted); }
  .sidenav a:hover { background: var(--surface-2); }
  .sidenav a[aria-current="page"] { background: var(--primary-soft); color: var(--primary); font-weight: 700; }
  .sidenav a[aria-current="page"] svg { color: var(--primary); }
  .sidenav .sep { height: 1px; background: var(--line); margin: 10px 4px; }
  .sidenav .quick { display: grid; gap: 6px; margin-top: 10px; }
  main.content { padding: 24px 28px 48px; }
  .topbar { padding: 0 20px; }
  .project-switch { flex: 0 1 420px; }
}

/* ---------------------------------------------------------------- components */
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.page-head p { margin: 4px 0 0; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 16px; }
.card h2 { margin-bottom: 10px; }
.section { margin-top: 20px; }
.section > h2 { margin-bottom: 10px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 0 16px;
  border-radius: 10px; border: 1px solid var(--line-strong); background: var(--surface); color: var(--text);
  font-weight: 600; cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn svg { width: 20px; height: 20px; flex: none; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-hover); }
.btn.danger { color: var(--danger); border-color: #e5b5b0; }
.btn.danger-solid { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.small { min-height: 36px; padding: 0 12px; font-size: .9rem; }
.btn.block { width: 100%; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.icon-btn {
  width: 44px; height: 44px; display: inline-flex; align-items: center; justify-content: center; border-radius: 10px;
  border: 0; background: transparent; cursor: pointer; color: var(--text); flex: none;
}
.icon-btn svg { width: 22px; height: 22px; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }

.badge {
  display: inline-flex; align-items: center; gap: 4px; font-size: .78rem; font-weight: 700; padding: 3px 8px;
  border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line); color: var(--muted); white-space: nowrap;
}
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; opacity: .8; }
.badge.ok { background: var(--ok-soft); border-color: #bfe0cb; color: var(--ok); }
.badge.warn { background: var(--warn-soft); border-color: #f0dca5; color: var(--warn); }
.badge.danger { background: var(--danger-soft); border-color: #f1c3be; color: var(--danger); }
.badge.info { background: var(--info-soft); border-color: #c6d9ec; color: var(--info); }
.badge.plain::before { display: none; }

.alert { border-radius: 10px; padding: 12px 14px; border: 1px solid; display: flex; gap: 10px; align-items: flex-start; }
.alert svg { width: 20px; height: 20px; flex: none; margin-top: 1px; }
.alert.danger { background: var(--danger-soft); border-color: #f1c3be; color: #7c1a13; }
.alert.warn { background: var(--warn-soft); border-color: #f0dca5; color: #5c3b00; }
.alert.info { background: var(--info-soft); border-color: #c6d9ec; color: #183f62; }
.alert.ok { background: var(--ok-soft); border-color: #bfe0cb; color: #164f2e; }
.alerts > * + * { margin-top: 8px; }

/* KPI */
.kpis { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
@media (min-width: 700px) { .kpis { grid-template-columns: repeat(3, 1fr); } }
.kpi { padding: 14px; }
.kpi .lab { font-size: .82rem; color: var(--muted); font-weight: 600; }
.kpi .val { font-size: 1.35rem; font-weight: 750; margin-top: 2px; font-variant-numeric: tabular-nums; }
.kpi .sub { font-size: .8rem; color: var(--muted); margin-top: 2px; }
.kpi.main { background: var(--primary); color: #fff; border-color: var(--primary); }
.kpi.main .lab, .kpi.main .sub { color: rgba(255,255,255,.85); }
.kpi.bad { border-color: #f1c3be; background: var(--danger-soft); }
.kpi.bad .val { color: var(--danger); }
.progress { height: 8px; background: var(--line); border-radius: 99px; overflow: hidden; margin-top: 8px; }
.progress > span { display: block; height: 100%; background: var(--primary); }

/* listes */
.list { display: grid; gap: 8px; }
.item {
  display: flex; gap: 12px; align-items: flex-start; padding: 12px 14px; background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius); text-decoration: none; color: inherit; cursor: pointer;
}
.item:hover { border-color: var(--line-strong); }
.item .main { flex: 1; min-width: 0; }
.item .title { font-weight: 650; overflow-wrap: anywhere; }
.item .meta { font-size: .85rem; color: var(--muted); margin-top: 2px; overflow-wrap: anywhere; }
.item .amount { text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.item .badges { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.empty { text-align: center; padding: 32px 16px; color: var(--muted); border: 1px dashed var(--line-strong); border-radius: var(--radius); background: var(--surface); }
.empty .btn { margin-top: 12px; }

.filters { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 12px; scrollbar-width: none; }
.filters::-webkit-scrollbar { display: none; }
.chip {
  border: 1px solid var(--line-strong); background: var(--surface); border-radius: 999px; padding: 7px 13px;
  font-size: .88rem; font-weight: 600; white-space: nowrap; cursor: pointer; min-height: 38px;
}
.chip[aria-pressed="true"] { background: var(--primary); color: #fff; border-color: var(--primary); }
.filter-bar { display: grid; gap: 8px; grid-template-columns: 1fr 1fr; margin-bottom: 12px; }
.filter-bar .full { grid-column: 1 / -1; }
@media (min-width: 900px) { .filter-bar { grid-template-columns: repeat(5, 1fr); } .filter-bar .full { grid-column: auto; } }

/* tableaux */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.t { width: 100%; border-collapse: collapse; font-size: .92rem; }
table.t th, table.t td { padding: 9px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
table.t th { font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); background: var(--surface-2); }
table.t td.num, table.t th.num { text-align: right; }
table.t tfoot td { font-weight: 700; background: var(--surface-2); }

.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; }
.kv dt { color: var(--muted); font-size: .9rem; }
.kv dd { margin: 0; font-weight: 600; text-align: right; font-variant-numeric: tabular-nums; }
.split { display: grid; gap: 16px; }
@media (min-width: 900px) { .split { grid-template-columns: 1fr 1fr; } .split.wide-left { grid-template-columns: 3fr 2fr; } }

.bar { height: 10px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 99px; overflow: hidden; position: relative; }
.bar > span { position: absolute; left: 0; top: 0; bottom: 0; background: var(--primary); }
.bar > span.paid { background: #6aa784; }
.bar.over > span { background: var(--danger); }

.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { padding: 8px 0; border-bottom: 1px solid var(--line); font-size: .9rem; }
.timeline li:last-child { border-bottom: 0; }
.timeline .when { color: var(--muted); font-size: .8rem; }

/* ---------------------------------------------------------------- formulaires */
.field { display: block; }
.field > label, .field > .label { display: block; font-weight: 600; font-size: .9rem; margin-bottom: 5px; }
.field .hint { font-size: .8rem; color: var(--muted); margin-top: 4px; }
.field .err { font-size: .85rem; color: var(--danger); margin-top: 4px; font-weight: 600; }
.input, select.input, textarea.input {
  width: 100%; min-height: 46px; padding: 10px 12px; border: 1px solid var(--line-strong); border-radius: 10px;
  background: #fff; font-size: 16px;
}
textarea.input { min-height: 84px; resize: vertical; }
.input:focus { outline: 3px solid rgba(31, 81, 53, .25); border-color: var(--primary); }
.input.invalid { border-color: var(--danger); }
.input.suggested { background: #fffbea; border-color: #e3c25a; }
.amount-input { position: relative; }
.amount-input .input { padding-right: 36px; text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.amount-input::after { content: "€"; position: absolute; right: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.form-grid { display: grid; gap: 14px; }
@media (min-width: 600px) { .form-grid.two { grid-template-columns: 1fr 1fr; } .form-grid .full { grid-column: 1 / -1; } }
.check { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface-2); cursor: pointer; }
.check input { width: 22px; height: 22px; margin: 1px 0 0; flex: none; accent-color: var(--primary); }
.sugg-tag { font-size: .72rem; font-weight: 700; color: #7a5b00; background: #fff1bf; border-radius: 6px; padding: 1px 6px; margin-left: 6px; }
.sugg-tag.low { color: var(--danger); background: var(--danger-soft); }
.calc { background: var(--primary-soft); border-radius: 10px; padding: 10px 12px; font-size: .92rem; }
.seg { display: flex; border: 1px solid var(--line-strong); border-radius: 10px; overflow: hidden; }
.seg button { flex: 1; min-height: 44px; border: 0; background: #fff; font-weight: 600; cursor: pointer; border-right: 1px solid var(--line); }
.seg button:last-child { border-right: 0; }
.seg button[aria-pressed="true"] { background: var(--primary); color: #fff; }

/* zone document */
.dropzone { border: 2px dashed var(--line-strong); border-radius: var(--radius); padding: 14px; background: var(--surface-2); }
.dropzone.drag { border-color: var(--primary); background: var(--primary-soft); }
.doc-status svg { width: 18px; height: 18px; }
.doc-status { display: flex; align-items: center; gap: 10px; font-size: .92rem; }
.spinner { width: 20px; height: 20px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--primary); animation: spin .8s linear infinite; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }
.doc-preview { background: #eef0ec; border-radius: 10px; overflow: auto; max-height: 70vh; text-align: center; border: 1px solid var(--line); }
.doc-preview img { max-width: 100%; display: block; margin: 0 auto; }
.thumb { width: 52px; height: 52px; border-radius: 8px; object-fit: cover; background: #eef0ec; border: 1px solid var(--line); flex: none; display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: .7rem; font-weight: 700; overflow: hidden; }
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(88px, 1fr)); gap: 8px; }
.photos button { padding: 0; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; aspect-ratio: 1; background: #eef0ec; cursor: pointer; }
.photos img { width: 100%; height: 100%; object-fit: cover; display: block; }

/* ---------------------------------------------------------------- modales */
.modal-backdrop { position: fixed; inset: 0; background: rgba(15, 25, 18, .45); z-index: 80; display: flex; align-items: flex-end; justify-content: center; }
.modal {
  background: var(--surface); width: 100%; max-height: 100%; height: 100%; display: flex; flex-direction: column;
  border-radius: 0; box-shadow: 0 10px 40px rgba(0,0,0,.25);
}
.modal.sheet { height: auto; max-height: 92%; border-radius: 16px 16px 0 0; }
.modal-head { display: flex; align-items: center; gap: 8px; padding: 10px 8px 10px 16px; border-bottom: 1px solid var(--line); padding-top: max(10px, env(safe-area-inset-top)); }
.modal-head h2 { flex: 1; font-size: 1.08rem; }
.modal-body { flex: 1; overflow: auto; padding: 16px; -webkit-overflow-scrolling: touch; }
.modal-foot {
  display: flex; gap: 8px; padding: 10px 16px; border-top: 1px solid var(--line); background: var(--surface);
  padding-bottom: max(10px, env(safe-area-inset-bottom));
}
.modal-foot .btn { flex: 1; }
.modal-foot .btn.primary { flex: 2; }
@media (min-width: 700px) {
  .modal-backdrop { align-items: center; padding: 24px; }
  .modal, .modal.sheet { height: auto; max-height: calc(100vh - 48px); width: 640px; border-radius: 16px; }
  .modal.wide { width: min(1140px, 100%); }
  .modal-foot .btn { flex: 0 0 auto; }
  .modal-foot { justify-content: flex-end; }
}
.with-preview { display: grid; gap: 16px; }
@media (min-width: 1000px) {
  .with-preview.has-doc { grid-template-columns: minmax(0, 1fr) minmax(0, 1.05fr); }
  .with-preview.has-doc .doc-col { order: 2; position: sticky; top: 0; align-self: start; }
}
.action-list { display: grid; gap: 8px; }
.action-list button {
  display: flex; gap: 14px; align-items: center; padding: 14px; border: 1px solid var(--line); border-radius: 12px;
  background: var(--surface); text-align: left; cursor: pointer; font-weight: 650; min-height: 60px;
}
.action-list button svg { width: 26px; height: 26px; color: var(--primary); flex: none; }
.action-list button small { display: block; font-weight: 400; color: var(--muted); font-size: .82rem; }

.toast-wrap { position: fixed; left: 0; right: 0; bottom: calc(var(--nav-h) + 84px); z-index: 100; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; padding: 0 16px; }
@media (min-width: 900px) { .toast-wrap { bottom: 24px; } }
.toast { pointer-events: auto; background: #1b231e; color: #fff; padding: 12px 16px; border-radius: 10px; box-shadow: var(--shadow); max-width: 520px; display: flex; gap: 12px; align-items: center; font-size: .95rem; }
.toast.error { background: var(--danger); }
.toast.ok { background: var(--ok); }
.toast button { background: rgba(255,255,255,.18); border: 0; color: #fff; padding: 6px 10px; border-radius: 6px; font-weight: 700; cursor: pointer; }

/* auth */
.auth { max-width: 420px; margin: 0 auto; padding: 48px 16px; }
.auth .logo { width: 64px; height: 64px; border-radius: 16px; margin-bottom: 16px; }
.auth h1 { margin-bottom: 6px; }

.project-card { padding: 16px; display: block; text-decoration: none; color: inherit; }
.project-card:hover { border-color: var(--line-strong); }
.project-grid { display: grid; gap: 12px; }
@media (min-width: 700px) { .project-grid { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 1100px) { .project-grid { grid-template-columns: repeat(3, 1fr); } }
.mini-kv { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 12px; font-size: .85rem; }
.mini-kv b { display: block; font-size: 1rem; font-variant-numeric: tabular-nums; }

.detail-amounts { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
@media (min-width: 700px) { .detail-amounts { grid-template-columns: repeat(4, 1fr); } }
.detail-amounts > div { background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.detail-amounts .lab { font-size: .78rem; color: var(--muted); font-weight: 600; }
.detail-amounts .val { font-size: 1.12rem; font-weight: 750; font-variant-numeric: tabular-nums; }

.loading-block { display: flex; gap: 10px; align-items: center; justify-content: center; padding: 40px; color: var(--muted); }
.error-block { text-align: center; padding: 32px 16px; }

@media print {
  .topbar, .sidenav, .bottomnav, .fab, .no-print, #toast-root { display: none !important; }
  body { background: #fff; }
  main.content { padding: 0; max-width: none; }
  .card { box-shadow: none; }
}
