:root {
  --bg: #f6f4ef; --surface: #ffffff; --ink: #1d2320; --muted: #6b716d; --line: #e4e0d7;
  --accent: #1f5c4d; --accent-ink: #ffffff; --accent-soft: #e2eee9;
  --warn: #9a5b00; --warn-bg: #fdf0d8; --bad: #a3271f; --bad-bg: #fbe3e0; --ok: #1f6b3a; --ok-bg: #e0f2e6;
  --radius: 12px; --nav-h: 62px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141816; --surface: #1d2220; --ink: #e9ece9; --muted: #9aa29d; --line: #2d3430;
    --accent: #5fb39b; --accent-ink: #0d1412; --accent-soft: #1f322c;
    --warn: #f0b75a; --warn-bg: #3a2c12; --bad: #f08a80; --bad-bg: #3b1d1a; --ok: #7fd39b; --ok-bg: #18301f;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 16px);
}
a { color: var(--accent); text-decoration: none; }
h1 { font-size: 1.45rem; margin: 0; line-height: 1.2; }
h2 { font-size: 1.05rem; margin: 26px 0 8px; }
h1 small, h2 small { color: var(--muted); font-weight: 500; font-size: .8em; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.pre { white-space: pre-wrap; }

main { max-width: 760px; margin: 0 auto; padding: 14px 16px; }

/* En-tête */
.top {
  position: sticky; top: 0; z-index: 10; display: flex; gap: 12px; align-items: center;
  padding: calc(8px + env(safe-area-inset-top)) 16px 8px; background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; color: var(--ink); }
.search { flex: 1; }
.search input, .search.inline input { width: 100%; }
.search.inline { margin: 8px 0 4px; }
@media (max-width: 520px) { .brand { font-size: 0; gap: 0; } }

/* Navigation basse */
.bottom {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 10; display: flex;
  background: var(--surface); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.bottom a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  height: var(--nav-h); font-size: .72rem; color: var(--muted);
}
.bottom a span { font-size: 1.3rem; line-height: 1.2; filter: grayscale(1); opacity: .7; }
.bottom a.on { color: var(--accent); font-weight: 600; }
.bottom a.on span { filter: none; opacity: 1; }

/* Blocs */
.bar { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin: 4px 0 14px; }
.back { font-weight: 600; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin: 10px 0; }
.note { background: var(--accent-soft); border-radius: var(--radius); padding: 10px 14px; }
.flash { background: var(--accent-soft); border-left: 4px solid var(--accent); border-radius: 8px; padding: 10px 14px; margin-bottom: 12px; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 380px) { .grid2 { grid-template-columns: 1fr; } }
.actions { display: flex; justify-content: space-between; gap: 12px; margin-top: 28px; flex-wrap: wrap; }
.inlineform { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.inlineform > input, .inlineform > select { flex: 1; min-width: 120px; }
.inlineform .emoji { flex: 0 0 64px; min-width: 0; text-align: center; }
.foot { margin-top: 16px; text-align: center; }

details > summary { cursor: pointer; font-weight: 600; color: var(--accent); list-style: none; }
details > summary::-webkit-details-marker { display: none; }
details[open] > summary { margin-bottom: 12px; }
.card > details { margin: 0; }

/* Formulaires */
label { display: flex; flex-direction: column; gap: 4px; font-size: .85rem; color: var(--muted); }
input, select, textarea {
  font: inherit; font-size: 16px; color: var(--ink); background: var(--bg);
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; width: 100%;
}
input[type=file] { padding: 8px; background: transparent; }
input[type=checkbox] { width: auto; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.checklist { max-height: 260px; overflow: auto; border: 1px solid var(--line); border-radius: 10px; padding: 6px 10px; }
.checklist label { flex-direction: row; align-items: center; gap: 10px; color: var(--ink); font-size: .95rem; padding: 6px 0; }

/* Boutons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: inherit; font-weight: 600; font-size: .95rem; cursor: pointer;
  padding: 10px 16px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); white-space: nowrap;
}
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--bad); border-color: var(--bad-bg); background: transparent; }
.btn.sm { padding: 6px 10px; font-size: .85rem; }
.btn.block { display: flex; margin: 10px 0; }
.icon { border: 0; background: none; color: var(--muted); font-size: 1rem; padding: 8px; cursor: pointer; }

/* Listes */
.list { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.list > li + li { border-top: 1px solid var(--line); }
.row { display: flex; align-items: center; gap: 12px; padding: 10px 12px; color: var(--ink); min-height: 60px; }
.row.col { flex-direction: column; align-items: stretch; gap: 4px; }
.rowlink, .grow.rowlink { display: flex; flex-direction: row; align-items: center; gap: 12px; color: var(--ink); min-width: 0; }
.rowtop { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.grow { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.grow strong, .grow .muted { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.end { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; font-weight: 600; font-size: .92rem; }
.empty { padding: 22px; text-align: center; color: var(--muted); }
.empty .btn { margin-top: 10px; }

.thumb { width: 46px; height: 46px; border-radius: 10px; object-fit: cover; flex: none; background: var(--bg); }
.thumb.sm { width: 36px; height: 36px; }
.ph { display: flex; align-items: center; justify-content: center; font-size: 1.4rem; background: var(--accent-soft); }

/* Chips & badges */
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 10px; margin: 0 -16px; padding-left: 16px; padding-right: 16px; scrollbar-width: none; }
.chip { flex: none; padding: 6px 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); font-size: .88rem; }
.chip.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: .74rem; font-weight: 600; background: var(--line); color: var(--ink); vertical-align: middle; }
.badge.ok, .badge.st-termine { background: var(--ok-bg); color: var(--ok); }
.badge.warn, .badge.st-en_cours { background: var(--warn-bg); color: var(--warn); }
.badge.bad { background: var(--bad-bg); color: var(--bad); }
.badge.st-planifie { background: var(--accent-soft); color: var(--accent); }

/* Fiche objet */
.hero { display: flex; gap: 14px; align-items: center; margin-bottom: 6px; }
.hero > img, .hero > .ph { width: 96px; height: 96px; border-radius: 16px; object-fit: cover; flex: none; font-size: 2.6rem; }
.hero p { margin: 4px 0; }
.facts { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; margin: 14px 0; }
.facts:empty { display: none; }
.facts dt { color: var(--muted); font-size: .88rem; }
.facts dd { margin: 0; }

/* Documents */
.preview img { width: 100%; max-height: 60vh; object-fit: contain; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line); }
.filecard { display: flex; align-items: center; gap: 10px; font-size: 1.1rem; color: var(--ink); }
.filecard .grow { font-size: .95rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: block; }
.ocr { white-space: pre-wrap; font-size: .78rem; max-height: 320px; overflow: auto; background: var(--bg); padding: 10px; border-radius: 8px; }

/* Projets */
.meter { display: block; height: 8px; background: var(--line); border-radius: 99px; overflow: hidden; margin: 6px 0 2px; }
.meter > span { display: block; height: 100%; background: var(--accent); border-radius: 99px; }
.meter > span.over { background: var(--bad); }
.budget strong { font-size: 1.3rem; }
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 8px; }
.gallery a > * { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 10px; }
.gallery .ph { flex-direction: column; font-size: 1.6rem; padding: 6px; }
.gallery .ph small { font-size: .7rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }

/* Connexion */
body.auth { padding-bottom: 0; }
.authbox { max-width: 360px; margin: 12vh auto 0; text-align: center; }
.authbox h1 { margin: 10px 0 18px; }
.authbox form { text-align: left; }

/* Étiquettes */
.labels { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px; }
.label { display: flex; align-items: center; gap: 10px; background: #fff; color: #000; border: 1px dashed #bbb; border-radius: 8px; padding: 8px; break-inside: avoid; }
.label img { width: 84px; height: 84px; flex: none; }
.label strong { display: block; font-size: .95rem; line-height: 1.2; }
.label span { font-size: .78rem; color: #444; }
@media print {
  .top, .bottom, .noprint, .flash { display: none !important; }
  body { background: #fff; padding: 0; }
  main { max-width: none; padding: 0; }
  .labels { grid-template-columns: repeat(3, 1fr); gap: 4mm; }
  .label { border-color: #999; }
}
