:root {
  --bg: #f4f6f5;
  --card: #fff;
  --text: #1c2624;
  --muted: #5f6d6a;
  --line: #e1e6e4;
  --primary: #0f766e;
  --primary-soft: #e3f2ef;
  --danger: #b42318;
  --danger-soft: #fdecea;
  --warn: #a15c07;
  --warn-soft: #fef3dc;
  --ok: #217a3c;
  --ok-soft: #e5f4e8;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 22, .06), 0 2px 8px rgba(16, 24, 22, .04);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111716; --card: #1a2220; --text: #e7eeec; --muted: #9aa8a5; --line: #2b3533;
    --primary: #3cb4a6; --primary-soft: #183330; --danger: #f08a80; --danger-soft: #3a1f1d;
    --warn: #f0b860; --warn-soft: #3a2c14; --ok: #6fcf8a; --ok-soft: #1a3322;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--text); line-height: 1.45; font-size: 16px;
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
}
a { color: var(--primary); }
h1 { font-size: 1.5rem; margin: .2rem 0 1rem; }
h2 { font-size: 1.15rem; margin: 1.4rem 0 .6rem; }
h3 { font-size: 1rem; margin: 0 0 .3rem; }
.container { max-width: 980px; margin: 0 auto; padding: 16px; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }

/* Barre de navigation : en bas sur mobile, en haut sur grand écran */
.topbar { background: var(--card); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 10px; padding: 12px 16px; font-weight: 700; color: var(--text); text-decoration: none; }
.logo { width: 28px; height: 28px; border-radius: 8px; background: var(--primary); color: #fff; display: grid; place-items: center; font-size: 22px; line-height: 1; }
.nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 10; display: flex;
  background: var(--card); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
}
.nav a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 4px; font-size: .72rem; color: var(--muted); text-decoration: none; }
.nav a .ico { font-size: 1.25rem; line-height: 1.2; }
.nav a.active { color: var(--primary); font-weight: 600; }
@media (min-width: 760px) {
  body { padding-bottom: 0; }
  .topbar { display: flex; align-items: center; justify-content: space-between; padding: 0 16px; position: sticky; top: 0; z-index: 10; }
  .topbar[hidden] { display: none; }
  .nav { position: static; border: 0; gap: 4px; padding: 0; }
  .nav a { flex-direction: row; font-size: .95rem; padding: 10px 14px; border-radius: 10px; gap: 6px; }
  .nav a .ico { font-size: 1rem; }
  .nav a.active { background: var(--primary-soft); }
}

/* Composants */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.stack > * + * { margin-top: 12px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.grid { display: grid; gap: 12px; }
@media (min-width: 640px) { .grid-2 { grid-template-columns: 1fr 1fr; } }
@media (min-width: 640px) { .items { grid-template-columns: 1fr 1fr; } }
@media (min-width: 900px) { .items { grid-template-columns: 1fr 1fr 1fr; } }

.btn {
  appearance: none; border: 1px solid var(--line); background: var(--card); color: var(--text);
  padding: 10px 16px; border-radius: 10px; font: inherit; font-weight: 600; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; text-decoration: none; min-height: 44px;
}
.btn:hover { border-color: var(--primary); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.danger { color: var(--danger); border-color: var(--danger-soft); background: var(--danger-soft); }
.btn.block { width: 100%; }
.btn.sm { padding: 6px 10px; min-height: 36px; font-size: .9rem; }
.btn:disabled { opacity: .6; cursor: default; }

label { display: block; font-weight: 600; font-size: .9rem; margin-bottom: 4px; }
input, select, textarea {
  width: 100%; font: inherit; color: var(--text); background: var(--card);
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; min-height: 44px;
}
textarea { min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus, .btn:focus-visible { outline: 2px solid var(--primary); outline-offset: 1px; }
.field { margin-bottom: 12px; }
.hint { font-size: .8rem; color: var(--muted); margin-top: 4px; }
.error { color: var(--danger); font-size: .9rem; min-height: 1.2em; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 16px; }
.stat { text-align: center; padding: 12px 6px; cursor: pointer; }
.stat b { display: block; font-size: 1.6rem; }
.stat span { font-size: .8rem; color: var(--muted); }
.stat.on { outline: 2px solid var(--primary); }
.stat.danger b { color: var(--danger); }
.stat.warn b { color: var(--warn); }

.item { display: flex; gap: 12px; text-decoration: none; color: inherit; align-items: flex-start; }
.item:hover { border-color: var(--primary); }
.thumb { width: 64px; height: 64px; border-radius: 10px; background: var(--primary-soft); flex-shrink: 0; object-fit: cover; display: grid; place-items: center; font-size: 28px; overflow: hidden; }
.thumb.lg { width: 100%; max-width: 280px; height: 200px; object-fit: contain; background: #fff; border: 1px solid var(--line); }
.item h3 { font-size: .98rem; word-break: break-word; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: .78rem; font-weight: 600; white-space: nowrap; }
.badge.perime { background: var(--danger-soft); color: var(--danger); }
.badge.bientot { background: var(--warn-soft); color: var(--warn); }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.inconnu { background: var(--line); color: var(--muted); }

.tabs { display: flex; background: var(--line); border-radius: 12px; padding: 4px; margin-bottom: 16px; }
.tabs button { flex: 1; border: 0; background: transparent; padding: 10px; border-radius: 9px; font: inherit; font-weight: 600; color: var(--muted); cursor: pointer; }
.tabs button.on { background: var(--card); color: var(--text); box-shadow: var(--shadow); }

.scanner { position: relative; background: #000; border-radius: var(--radius); overflow: hidden; aspect-ratio: 4 / 3; max-height: 60vh; }
.scanner video { width: 100%; height: 100%; object-fit: cover; display: block; }
.scanner .frame { position: absolute; inset: 22% 22%; border: 3px solid rgba(255,255,255,.85); border-radius: 12px; box-shadow: 0 0 0 999px rgba(0,0,0,.35); }

.suggest { list-style: none; margin: 6px 0 0; padding: 0; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--card); }
.suggest li { padding: 10px 12px; border-bottom: 1px solid var(--line); cursor: pointer; }
.suggest li:last-child { border-bottom: 0; }
.suggest li:hover, .suggest li:focus { background: var(--primary-soft); outline: none; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { border: 1px solid var(--line); background: var(--card); color: var(--text); border-radius: 99px; padding: 8px 14px; font: inherit; font-size: .9rem; cursor: pointer; }
.chip.on { background: var(--primary); border-color: var(--primary); color: #fff; }

.images { display: grid; grid-template-columns: repeat(auto-fill, minmax(90px, 1fr)); gap: 8px; }
.images button { padding: 0; border: 2px solid var(--line); border-radius: 10px; overflow: hidden; background: #fff; cursor: pointer; aspect-ratio: 1; }
.images button.on { border-color: var(--primary); }
.images img { width: 100%; height: 100%; object-fit: contain; }

.alert { border-radius: 12px; padding: 12px 14px; font-size: .92rem; }
.alert.danger { background: var(--danger-soft); color: var(--danger); }
.alert.warn { background: var(--warn-soft); color: var(--warn); }
.alert.info { background: var(--primary-soft); color: var(--text); }
dl.info { margin: 0; }
dl.info dt { font-weight: 700; font-size: .85rem; color: var(--muted); margin-top: 10px; }
dl.info dd { margin: 2px 0 0; }

.auth { max-width: 420px; margin: 6vh auto; }
.auth .logo { width: 48px; height: 48px; font-size: 36px; border-radius: 12px; margin: 0 auto 12px; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(84px + env(safe-area-inset-bottom));
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; z-index: 20; max-width: 90vw;
}
@media (min-width: 760px) { .toast { bottom: 24px; } }
.empty { text-align: center; padding: 32px 16px; }
.notice details { border-top: 1px solid var(--line); padding: 8px 0; }
.notice summary { cursor: pointer; }
.notice-body { font-size: .9rem; margin-top: 6px; overflow-x: auto; }
.notice-body p { margin: .4em 0; }
.notice-body table { border-collapse: collapse; }
.notice-body td, .notice-body th { border: 1px solid var(--line); padding: 4px 6px; }
.clamp { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.nav a span { white-space: nowrap; }
