:root {
  --bg: #f6f4ee;
  --card: #ffffff;
  --ink: #1f2a1c;
  --muted: #6b7365;
  --line: #e2ded2;
  --brand: #2f4a2a;
  --brand-ink: #ffffff;
  --accent: #b5562b;
  --ok: #3f7d3a;
  --warn: #b7791f;
  --bad: #9b2c2c;
  --idea: #4a5d8a;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 2px 8px rgba(0,0,0,.04);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141712;
    --card: #1d211a;
    --ink: #e9ebe4;
    --muted: #9aa392;
    --line: #2f352b;
    --brand: #8fbf7f;
    --brand-ink: #10140e;
    --accent: #e08a5e;
    --ok: #8fbf7f;
    --warn: #e0b45e;
    --bad: #e07a7a;
    --idea: #9fb1e0;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  padding-bottom: env(safe-area-inset-bottom);
}
a { color: inherit; }
h1, h2, h3 { line-height: 1.2; margin: 0; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; }
.muted { color: var(--muted); }
.center { text-align: center; }
[hidden] { display: none !important; }

/* ---------- En-tête */
.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  -webkit-backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; text-decoration: none; font-weight: 650; color: var(--brand); min-width: 0; }
.brand span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand svg { width: 22px; height: 22px; flex: none; }

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

/* ---------- Boutons */
button, .btn {
  font: inherit; border: 0; border-radius: 10px; padding: 10px 16px; cursor: pointer;
  text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px;
}
.primary { background: var(--brand); color: var(--brand-ink); font-weight: 600; }
.ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); }
.danger { background: transparent; color: var(--bad); border: 1px solid currentColor; }
.small { padding: 6px 12px; min-height: 36px; font-size: .9rem; }
button:disabled { opacity: .5; }

/* ---------- Cartes et listes */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.stack > * + * { margin-top: 12px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
section + section { margin-top: 24px; }
section > h3 { margin: 0 0 8px 4px; }

.search { width: 100%; font: inherit; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); color: var(--ink); }
.chips { display: flex; gap: 6px; overflow-x: auto; padding: 10px 0 2px; -webkit-overflow-scrolling: touch; }
.chip { flex: none; border: 1px solid var(--line); background: var(--card); color: var(--ink); border-radius: 999px; padding: 6px 12px; min-height: 34px; font-size: .9rem; }
.chip[aria-pressed="true"] { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }

.list { list-style: none; margin: 0; padding: 0; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.list li + li { border-top: 1px solid var(--line); }
.list a { display: flex; align-items: center; gap: 12px; padding: 12px 14px; text-decoration: none; min-height: 56px; }
.list a:active { background: color-mix(in srgb, var(--brand) 8%, transparent); }
.list .main { flex: 1; min-width: 0; }
.list .t { display: block; font-weight: 600; }
.list .s { display: block; color: var(--muted); font-size: .88rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list img { width: 44px; height: 44px; border-radius: 8px; object-fit: cover; flex: none; }

.code { font: 600 .82rem/1 ui-monospace, SFMono-Regular, Menlo, monospace; background: color-mix(in srgb, var(--brand) 14%, transparent); color: var(--brand); border-radius: 6px; padding: 5px 7px; flex: none; min-width: 3.4em; text-align: center; }
.pill { display: inline-block; font-size: .78rem; font-weight: 600; border-radius: 999px; padding: 2px 9px; border: 1px solid currentColor; white-space: nowrap; }
.st-en-place { color: var(--ok); }
.st-a-remplacer { color: var(--warn); }
.st-mort { color: var(--bad); }
.st-projete { color: var(--idea); }

/* ---------- Fiche */
.hero { margin: -16px -16px 16px; position: relative; }
.hero img { width: 100%; max-height: 52vh; object-fit: cover; display: block; }
.title-block { margin-bottom: 16px; }
.title-block .row { margin-bottom: 6px; }
.title-block h1 small { display: block; font-size: 1.05rem; font-weight: 500; color: var(--muted); margin-top: 4px; }
dl.facts { display: grid; grid-template-columns: max-content 1fr; gap: 8px 16px; margin: 0; }
dl.facts dt { color: var(--muted); }
dl.facts dd { margin: 0; font-weight: 500; }
dl.facts .private dt::after { content: " 🔒"; font-size: .75em; }
.notes { white-space: pre-wrap; }

.thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(88px, 1fr)); gap: 6px; }
.thumbs figure { margin: 0; position: relative; }
.thumbs img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 8px; display: block; cursor: zoom-in; }
.thumbs .del { position: absolute; top: 4px; right: 4px; min-height: 0; width: 28px; height: 28px; padding: 0; border-radius: 50%; background: rgba(0,0,0,.65); color: #fff; font-size: 18px; line-height: 1; }
.thumbs .del[aria-pressed="true"] { background: var(--bad); }
.thumbs figure:has(.del[aria-pressed="true"]) img { opacity: .35; }

.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { position: relative; padding: 0 0 18px 22px; border-left: 2px solid var(--line); margin-left: 6px; }
.timeline li:last-child { border-left-color: transparent; }
.timeline li::before { content: ""; position: absolute; left: -7px; top: 4px; width: 12px; height: 12px; border-radius: 50%; background: var(--card); border: 2px solid var(--tc, var(--muted)); }
.timeline .head { display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.timeline .type { font-weight: 650; color: var(--tc, var(--ink)); }
.timeline .date { color: var(--muted); font-size: .9rem; }
.timeline .body { margin-top: 4px; white-space: pre-wrap; }
.timeline .thumbs { margin-top: 8px; }
.t-Récolte { --tc: var(--accent); }
.t-Taille { --tc: var(--ok); }
.t-Traitement { --tc: var(--idea); }
.t-Observation { --tc: var(--muted); }
.t-Plantation, .t-Remplacement { --tc: var(--warn); }
.timeline .del-entry { margin-left: auto; min-height: 0; padding: 2px 8px; font-size: .8rem; color: var(--muted); background: none; border: 0; }

.fab { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(18px + env(safe-area-inset-bottom)); z-index: 6; box-shadow: 0 6px 20px rgba(0,0,0,.2); padding: 14px 22px; border-radius: 999px; font-size: 1.05rem; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 16px; }
.stats div { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; }
.stats b { display: block; font-size: 1.4rem; font-variant-numeric: tabular-nums; }
.stats span { color: var(--muted); font-size: .82rem; }

/* ---------- Formulaires et dialogues */
dialog { border: 0; border-radius: 18px; padding: 20px; width: min(560px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); background: var(--card); color: var(--ink); box-shadow: 0 20px 60px rgba(0,0,0,.3); }
dialog::backdrop { background: rgba(0,0,0,.45); }
label { display: block; font-size: .88rem; color: var(--muted); }
label > input:not([type=checkbox]):not([type=radio]), label > select, label > textarea {
  display: block; width: 100%; margin-top: 4px; font: inherit; font-size: 16px; color: var(--ink);
  background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; min-height: 44px;
}
label.check { display: flex; gap: 10px; align-items: center; color: var(--ink); font-size: .95rem; }
label.check input { width: 22px; height: 22px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid2 .span2 { grid-column: span 2; }
@media (max-width: 420px) { .grid2 { grid-template-columns: 1fr; } .grid2 .span2 { grid-column: auto; } }
fieldset.types { border: 0; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
fieldset.types legend { font-size: .88rem; color: var(--muted); margin-bottom: 6px; }
fieldset.types label { margin: 0; }
fieldset.types input { position: absolute; opacity: 0; pointer-events: none; }
fieldset.types span { display: flex; align-items: center; justify-content: center; min-height: 44px; border: 1px solid var(--line); border-radius: 10px; color: var(--ink); font-size: .92rem; background: var(--bg); }
fieldset.types input:checked + span { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); font-weight: 600; }
fieldset.types input:focus-visible + span { outline: 2px solid var(--brand); outline-offset: 2px; }
.error { color: var(--bad); margin: 0; }

dialog.photo { padding: 0; width: auto; max-width: 100vw; max-height: 100dvh; background: #000; border-radius: 0; }
dialog.photo img { display: block; max-width: 100vw; max-height: 100dvh; object-fit: contain; }
dialog.photo .close { position: absolute; top: calc(8px + env(safe-area-inset-top)); right: 8px; background: rgba(0,0,0,.6); color: #fff; border-radius: 50%; width: 44px; height: 44px; padding: 0; font-size: 26px; }

#toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(90px + env(safe-area-inset-bottom)); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px; z-index: 20; max-width: calc(100vw - 32px); }

/* ---------- Étiquettes */
.tags-table { width: 100%; border-collapse: collapse; background: var(--card); border-radius: var(--radius); overflow: hidden; }
.tags-table td, .tags-table th { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; font-size: .92rem; }
.tags-table td.url { font-family: ui-monospace, Menlo, monospace; font-size: .8rem; word-break: break-all; }
@media print {
  .top, .fab, .noprint, button { display: none !important; }
  body { background: #fff; }
  main { padding: 0; max-width: none; }
}
