:root {
  --bg: #f4f6f5;
  --card: #ffffff;
  --text: #17211f;
  --muted: #64716e;
  --line: #e2e7e5;
  --brand: #0f766e;
  --brand-2: #14b8a6;
  --brand-soft: #e6f4f2;
  --danger: #c2410c;
  --warn-bg: #fff4e5;
  --warn: #9a5b00;
  --on-brand: #ffffff;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 16px rgba(0,0,0,.05);
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1513; --card: #17211e; --text: #e7efec; --muted: #94a39f; --line: #26332f;
    --brand: #2dd4bf; --brand-2: #5eead4; --brand-soft: #123530; --danger: #fb923c;
    --warn-bg: #3a2a10; --warn: #fcd34d; --on-brand: #06201c;
    --shadow: 0 1px 2px rgba(0,0,0,.4);
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--text);
  -webkit-tap-highlight-color: transparent;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
a { color: var(--brand); }

.splash { display: grid; place-items: center; height: 100vh; }
.splash img { animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { transform: scale(.92); opacity: .7; } }

/* --- en-tête --- */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px calc(10px);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
}
.topbar h1 { font-size: 20px; margin: 0; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .sub { display: block; font-size: 12.5px; font-weight: 500; color: var(--muted); }
.icon-btn {
  width: 42px; height: 42px; border-radius: 50%; border: 0; background: transparent;
  display: grid; place-items: center; font-size: 20px;
}
.icon-btn:active { background: var(--line); }
.icon-btn.light { color: #fff; background: rgba(0,0,0,.35); }
.avatar { width: 34px; height: 34px; border-radius: 50%; object-fit: cover; background: var(--brand-soft); display: grid; place-items: center; font-weight: 700; color: var(--brand); }

main { padding: 0 14px calc(120px + var(--safe-b)); max-width: 640px; margin: 0 auto; }

.banner {
  margin: 4px 0 12px; padding: 10px 14px; border-radius: var(--radius);
  background: var(--brand-soft); color: var(--brand); font-size: 14px;
}
.banner.warn { background: var(--warn-bg); color: var(--warn); }

/* --- ajout rapide --- */
.quick-add { display: flex; gap: 8px; margin-bottom: 14px; }
.quick-add input {
  flex: 1; min-width: 0; padding: 12px 14px; border-radius: var(--radius);
  border: 1px solid var(--line); background: var(--card);
}
.quick-add input:focus { outline: 2px solid var(--brand-2); border-color: transparent; }

.btn {
  border: 0; border-radius: 12px; padding: 11px 16px; font-weight: 600;
  background: var(--brand); color: var(--on-brand);
}
.btn:disabled { opacity: .5; }
.btn.ghost { background: transparent; color: var(--brand); border: 1px solid var(--line); }
.btn.danger { background: transparent; color: var(--danger); border: 1px solid var(--line); }
.btn.block { width: 100%; padding: 14px; }

/* --- liste --- */
.group { margin-bottom: 14px; }
.group h2 {
  font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted);
  margin: 0 4px 6px; font-weight: 700;
}
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.item {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px; min-height: 58px;
  border-bottom: 1px solid var(--line);
}
.item:last-child { border-bottom: 0; }
.check {
  flex: none; width: 28px; height: 28px; border-radius: 50%; border: 2px solid var(--brand);
  background: transparent; display: grid; place-items: center; color: var(--on-brand); font-size: 15px; padding: 0;
}
.item.done .check { background: var(--brand); }
.thumb { flex: none; width: 38px; height: 38px; border-radius: 8px; object-fit: contain; background: #fff; }
.thumb.ph { display: grid; place-items: center; background: var(--brand-soft); font-size: 20px; }
.item-main { flex: 1; min-width: 0; background: none; border: 0; text-align: left; padding: 4px 0; }
.item-name { display: block; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-meta { display: block; font-size: 12.5px; color: var(--muted); }
.item.done .item-name { text-decoration: line-through; color: var(--muted); font-weight: 500; }
.qty { flex: none; min-width: 30px; height: 26px; padding: 0 8px; border-radius: 13px; background: var(--brand-soft); color: var(--brand); font-weight: 700; font-size: 14px; display: grid; place-items: center; }

.basket-head { display: flex; align-items: center; justify-content: space-between; margin: 20px 4px 6px; }
.basket-head h2 { margin: 0; }
.link-btn { background: none; border: 0; color: var(--brand); font-weight: 600; padding: 6px; }

.empty { text-align: center; color: var(--muted); padding: 48px 20px; }
.empty .big { font-size: 48px; }

/* --- bouton scanner --- */
.fab {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(22px + var(--safe-b)); z-index: 6;
  display: flex; align-items: center; gap: 10px;
  border: 0; border-radius: 30px; padding: 16px 28px;
  background: var(--brand); color: var(--on-brand); font-weight: 700; font-size: 17px;
  box-shadow: 0 8px 24px rgba(15,118,110,.4);
}
.fab:active { transform: translateX(-50%) scale(.97); }
.fab:disabled { background: var(--muted); box-shadow: none; }

/* --- écrans d'accueil --- */
.center { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 24px; text-align: center; max-width: 440px; margin: 0 auto; }
.center h1 { margin: 16px 0 6px; font-size: 28px; }
.center p { color: var(--muted); margin: 0 0 24px; }
.center .card { width: 100%; padding: 18px; text-align: left; }
.field { display: block; margin-bottom: 12px; }
.field span { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 4px; }
.field input, .field select {
  width: 100%; padding: 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--card);
}
.or { color: var(--muted); font-size: 13px; margin: 14px 0; text-align: center; }
.fine { font-size: 12.5px; color: var(--muted); margin-top: 18px; }
#gbtn { display: flex; justify-content: center; min-height: 44px; }

/* --- fenêtre du bas --- */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 20; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 21;
  max-height: 88vh; overflow: auto; background: var(--card);
  border-radius: 20px 20px 0 0; padding: 10px 18px calc(20px + var(--safe-b));
  max-width: 640px; margin: 0 auto; animation: up .18s ease-out;
}
@keyframes up { from { transform: translateY(30px); opacity: 0; } }
.sheet .grip { width: 40px; height: 4px; border-radius: 2px; background: var(--line); margin: 0 auto 12px; }
.sheet h3 { margin: 4px 0 14px; font-size: 19px; }
.sheet .row { display: flex; gap: 10px; margin-top: 14px; }
.sheet .row > * { flex: 1; }
.stepper { display: flex; align-items: center; gap: 12px; }
.stepper button { width: 42px; height: 42px; border-radius: 50%; border: 1px solid var(--line); background: var(--card); font-size: 20px; }
.stepper output { min-width: 32px; text-align: center; font-weight: 700; font-size: 18px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1px solid var(--line); background: var(--card); border-radius: 18px; padding: 7px 11px; font-size: 14px; }
.chip.on { background: var(--brand); color: var(--on-brand); border-color: var(--brand); }
.product-head { display: flex; gap: 12px; align-items: center; margin-bottom: 12px; }
.product-head img { width: 56px; height: 56px; object-fit: contain; border-radius: 10px; background: #fff; }

/* --- réglages --- */
.section { margin: 18px 0 8px; font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 700; }
.list-row { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.list-row:last-child { border-bottom: 0; }
.list-row .grow { flex: 1; min-width: 0; }
.list-row small { display: block; color: var(--muted); }
.tag { font-size: 12px; padding: 2px 8px; border-radius: 10px; background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.token-box { font-family: ui-monospace, monospace; font-size: 13px; word-break: break-all; padding: 12px; border-radius: 10px; background: var(--bg); border: 1px dashed var(--line); user-select: all; }

/* --- scanner --- */
.scanner { position: fixed; inset: 0; z-index: 30; background: #000; color: #fff; }
.scanner video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.scanner video.mirror { transform: scaleX(-1); }
#scan-flip:active svg { transform: rotate(180deg); transition: transform .25s; }
.scan-frame { position: absolute; inset: 0; display: grid; place-items: center; pointer-events: none; }
.scan-frame span {
  width: min(78vw, 360px); height: min(40vw, 190px); border-radius: 18px;
  box-shadow: 0 0 0 100vmax rgba(0,0,0,.45); border: 3px solid rgba(255,255,255,.9);
}
.scanner.hit .scan-frame span { border-color: var(--brand-2); }
.scan-top { position: absolute; top: 0; left: 0; right: 0; display: flex; align-items: center; gap: 10px; padding: 14px; padding-top: max(14px, env(safe-area-inset-top)); }
.scan-hint { flex: 1; text-align: center; font-weight: 600; text-shadow: 0 1px 3px #000; }
.scan-bottom { position: absolute; left: 0; right: 0; bottom: 0; padding: 14px 14px calc(18px + var(--safe-b)); }
.scan-feed { display: flex; flex-direction: column; gap: 6px; margin-bottom: 10px; }
.scan-feed div { background: rgba(0,0,0,.6); border-radius: 12px; padding: 9px 12px; font-size: 14.5px; animation: up .18s; }
.scan-manual { display: flex; gap: 8px; }
.scan-manual input { flex: 1; min-width: 0; padding: 12px; border-radius: 12px; border: 0; background: rgba(255,255,255,.92); color: #111; }

.toast {
  position: fixed; left: 50%; bottom: calc(96px + var(--safe-b)); transform: translateX(-50%);
  z-index: 40; background: #1f2937; color: #fff; padding: 11px 16px; border-radius: 12px;
  font-size: 14.5px; max-width: calc(100vw - 32px); box-shadow: 0 6px 20px rgba(0,0,0,.25);
}
.toast button { background: none; border: 0; color: var(--brand-2); font-weight: 700; margin-left: 10px; }

.scanner.manual .scan-frame { display: none; }
