:root {
  --bg: #eef1ef;
  --surface: #ffffff;
  --ink: #15231f;
  --muted: #5b6b66;
  --line: #d5dcd8;
  --brand: #0e5a4a;
  --brand-dark: #0a4337;
  --in: #0e5a4a;
  --out: #1f3a5f;
  --ok: #1e7a46;
  --ok-bg: #ddf3e5;
  --warn: #8a5a00;
  --warn-bar: #e0a100;
  --warn-bg: #fff1cc;
  --bad: #b3261e;
  --bad-bg: #fde3e0;
  --radius: 10px;
  --nav-w: 232px;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 "Segoe UI", Roboto, "Helvetica Neue", Arial, system-ui, sans-serif;
  font-variant-numeric: tabular-nums;
}
h1, h2, h3 { margin: 0; line-height: 1.2; letter-spacing: -0.01em; }
h1 { font-size: 1.6rem; font-weight: 750; }
h2 { font-size: 1.15rem; font-weight: 700; }
a { color: var(--brand); }
small, .muted { color: var(--muted); }
small { font-size: 0.85rem; }
:focus-visible { outline: 3px solid #f2b705; outline-offset: 2px; }

/* ---------- Structure ---------- */
.app { min-height: 100vh; }
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: var(--brand); color: #fff;
}
.topbar .brand { font-weight: 750; font-size: 1.05rem; }
.topbar .who { font-size: 0.9rem; opacity: 0.9; }
.main { padding: 16px 16px calc(96px + env(safe-area-inset-bottom)); max-width: 980px; margin: 0 auto; }

.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex; background: var(--surface); 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 2px 7px; font-size: 0.72rem; font-weight: 600; text-decoration: none; color: var(--muted);
  border-top: 3px solid transparent;
}
.nav a svg { width: 24px; height: 24px; }
.nav a.active { color: var(--brand); border-top-color: var(--brand); }
.nav a.desk { display: none; }

@media (min-width: 900px) {
  .app { padding-left: var(--nav-w); }
  .topbar { position: fixed; top: 0; left: 0; right: 0; }
  .main { padding-top: 76px; padding-bottom: 40px; }
  .nav {
    top: 52px; bottom: 0; right: auto; width: var(--nav-w); flex-direction: column;
    border-top: 0; border-right: 1px solid var(--line); padding: 12px 8px; gap: 2px;
  }
  .nav a {
    flex: none; flex-direction: row; gap: 12px; padding: 12px 14px; font-size: 1rem;
    border-top: 0; border-left: 4px solid transparent; border-radius: 6px;
  }
  .nav a.active { background: #e3efeb; border-left-color: var(--brand); }
  .nav a.desk { display: flex; }
  .nav a.mobile-only { display: none; }
}

/* ---------- Éléments ---------- */
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 4px 0 14px; flex-wrap: wrap; }
.stack > * + * { margin-top: 14px; }
.row { display: flex; gap: 10px; align-items: stretch; }
.row > .input { flex: 1; min-width: 0; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.row3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
@media (max-width: 520px) { .row3 { grid-template-columns: 1fr; } }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.card + .card, .card + .section, .section + .card, .section + .section { margin-top: 14px; }
.section > h2 { margin: 18px 0 8px; }
.lbl { display: block; font-weight: 650; margin-bottom: 5px; font-size: 0.95rem; }
.hint { display: block; color: var(--muted); font-size: 0.85rem; margin-top: 4px; }

.input, select.input, textarea.input {
  width: 100%; min-height: 46px; padding: 10px 12px; font: inherit; color: var(--ink);
  background: #fff; border: 1.5px solid #aeb9b4; border-radius: 8px;
}
.input:focus { border-color: var(--brand); outline: 3px solid rgba(14, 90, 74, 0.2); outline-offset: 0; }
.input.big { min-height: 54px; font-size: 1.2rem; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 46px; padding: 10px 16px; font: inherit; font-weight: 650; cursor: pointer;
  color: var(--ink); background: #fff; border: 1.5px solid #aeb9b4; border-radius: 8px; text-decoration: none;
}
.btn:hover { background: #f3f6f4; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-dark); }
.btn.in { background: var(--in); border-color: var(--in); color: #fff; }
.btn.out { background: var(--out); border-color: var(--out); color: #fff; }
.btn.in:hover { background: var(--brand-dark); }
.btn.out:hover { background: #162b47; }
.btn.danger { color: var(--bad); border-color: var(--bad); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--brand); }
.btn.big { min-height: 58px; font-size: 1.15rem; width: 100%; }
.btn.small { min-height: 38px; padding: 6px 12px; font-size: 0.9rem; }
.btn svg { width: 22px; height: 22px; }

.badge {
  display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: 0.78rem; font-weight: 700;
  background: #e6ebe8; color: var(--muted); white-space: nowrap;
}
.badge.bad { background: var(--bad-bg); color: var(--bad); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.ok { background: var(--ok-bg); color: var(--ok); }

/* Accueil */
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 14px; }
.actions .btn { min-height: 76px; font-size: 1.3rem; }
.actions .btn svg { width: 28px; height: 28px; }
.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
@media (min-width: 700px) { .tiles { grid-template-columns: repeat(4, 1fr); } }
.tile {
  display: flex; flex-direction: column; gap: 2px; padding: 12px 14px; background: var(--surface);
  border: 1px solid var(--line); border-left: 6px solid var(--ok); border-radius: var(--radius);
  color: var(--ink); text-decoration: none;
}
.tile .n { font-size: 1.7rem; font-weight: 750; line-height: 1.1; }
.tile .t { color: var(--muted); font-size: 0.9rem; }
.tile.warn { border-left-color: var(--warn-bar); }
.tile.bad { border-left-color: var(--bad); }
.tile.neutral { border-left-color: var(--brand); }

/* Listes : la barre colorée à gauche rappelle l'étiquette de palette */
.list { display: flex; flex-direction: column; gap: 8px; }
.item {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 14px; background: var(--surface); border: 1px solid var(--line);
  border-left: 6px solid var(--ok); border-radius: var(--radius); color: var(--ink); text-decoration: none;
}
a.item:hover { background: #f8faf9; }
.item.warn { border-left-color: var(--warn-bar); }
.item.bad { border-left-color: var(--bad); }
.item.none { border-left-color: #b9c3be; }
.item .name { font-weight: 700; overflow-wrap: anywhere; }
.item .sub { color: var(--muted); font-size: 0.88rem; overflow-wrap: anywhere; }
.item .right { text-align: right; flex-shrink: 0; }
.item .qty { font-weight: 750; font-size: 1.05rem; }
.item .badges { display: flex; gap: 4px; flex-wrap: wrap; justify-content: flex-end; margin-top: 3px; }
.empty { padding: 28px 14px; text-align: center; color: var(--muted); }

.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; margin: 10px 0; }
.chip {
  flex: none; padding: 8px 14px; border: 1.5px solid #aeb9b4; background: #fff; border-radius: 99px;
  font: inherit; font-weight: 600; cursor: pointer; color: var(--ink);
}
.chip.on { background: var(--brand); border-color: var(--brand); color: #fff; }

/* Sélecteur de produit */
.results { margin-top: 8px; display: flex; flex-direction: column; gap: 6px; }
.result {
  display: block; width: 100%; text-align: left; padding: 11px 14px; font: inherit; cursor: pointer;
  background: #fff; border: 1px solid var(--line); border-radius: 8px; color: var(--ink);
}
.result:hover { background: #f3f6f4; }
.result .sub { display: block; color: var(--muted); font-size: 0.85rem; }
.result.create { border-style: dashed; border-color: var(--brand); color: var(--brand); font-weight: 700; }
.selected { border-left: 6px solid var(--brand); }
.selected .pname { font-size: 1.2rem; font-weight: 750; overflow-wrap: anywhere; }

.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 600; overflow-wrap: anywhere; }
.bigqty { font-size: 1.7rem; font-weight: 750; line-height: 1.15; }

.radio-list { display: flex; flex-direction: column; gap: 8px; }
.radio-item {
  display: flex; align-items: center; gap: 12px; padding: 12px; background: #fff; cursor: pointer;
  border: 1.5px solid var(--line); border-left: 6px solid var(--ok); border-radius: 8px;
}
.radio-item.warn { border-left-color: var(--warn-bar); }
.radio-item.bad { border-left-color: var(--bad); }
.radio-item.none { border-left-color: #b9c3be; }
.radio-item input { width: 22px; height: 22px; flex: none; accent-color: var(--brand); }
.radio-item:has(input:checked) { border-color: var(--brand); background: #f0f7f4; }

.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 0.85rem; color: var(--muted); font-weight: 650; background: #f6f8f7; }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; white-space: nowrap; }

/* Fenêtres */
.overlay {
  position: fixed; inset: 0; z-index: 100; background: rgba(10, 20, 17, 0.6);
  display: flex; align-items: center; justify-content: center; padding: 16px; overflow-y: auto;
}
.modal, .scanbox { background: #fff; border-radius: 12px; padding: 18px; width: 100%; max-width: 460px; max-height: 94vh; overflow-y: auto; }
.scanhead { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
#reader { width: 100%; min-height: 200px; background: #0f1a17; border-radius: 8px; overflow: hidden; }
#reader video { width: 100% !important; }

#toasts {
  position: fixed; left: 12px; right: 12px; bottom: calc(86px + env(safe-area-inset-bottom)); z-index: 200;
  display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none;
}
@media (min-width: 900px) { #toasts { bottom: 24px; } }
.toast {
  padding: 12px 18px; border-radius: 8px; color: #fff; background: var(--ink); font-weight: 600;
  max-width: 560px; box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
}
.toast.ok { background: var(--ok); }
.toast.err { background: var(--bad); }

/* Connexion */
.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; background: var(--brand); }
.login .card { width: 100%; max-width: 380px; padding: 24px; }
.login h1 { margin-bottom: 4px; }
.error { color: var(--bad); font-weight: 600; margin: 0; }

@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; transition: none !important; animation: none !important; } }
