:root {
  --bg: #0f1115;
  --surface: #181b22;
  --surface-2: #21252e;
  --border: #2c313c;
  --text: #e7e9ee;
  --muted: #9aa3b2;
  --accent: #19c37d;
  --danger: #ff5d5d;
  --danger-bg: #3a1d22;
  --radius: 14px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  padding-bottom: 76px;
}

.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 800; letter-spacing: 1px; color: var(--text); text-decoration: none; font-size: 19px; }
.brand span { color: var(--accent); }

.content { padding: 16px; max-width: 720px; margin: 0 auto; }

/* Boutons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: var(--accent); color: #042; border: none;
  padding: 12px 16px; border-radius: var(--radius);
  font-weight: 700; font-size: 15px; cursor: pointer; text-decoration: none;
}
.btn.ghost { background: transparent; color: var(--text); border: 1px solid var(--border); }
.btn.round { border-radius: 999px; padding: 10px 18px; }
.btn:active { transform: scale(.97); }

/* Recherche + filtres */
.searchbar { display: flex; gap: 8px; margin-bottom: 12px; }
.searchbar input {
  flex: 1; background: var(--surface); border: 1px solid var(--border);
  color: var(--text); padding: 12px 14px; border-radius: var(--radius); font-size: 15px;
}
.filters { display: flex; gap: 8px; margin-bottom: 16px; }
.chip {
  padding: 7px 14px; border-radius: 999px; text-decoration: none;
  background: var(--surface); color: var(--muted); border: 1px solid var(--border); font-size: 14px;
}
.chip.on { color: var(--text); border-color: var(--accent); }
.chip.danger.on { border-color: var(--danger); color: var(--danger); }

.empty { color: var(--muted); text-align: center; padding: 40px 0; }

/* Liste produits */
.cards { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 10px; }
.card a {
  display: flex; align-items: center; gap: 12px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 10px; text-decoration: none; color: var(--text);
}
.card.low a { border-color: var(--danger); }
.thumb {
  width: 54px; height: 54px; flex: 0 0 54px; border-radius: 10px;
  background: var(--surface-2); display: flex; align-items: center; justify-content: center;
  overflow: hidden; font-size: 24px;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb.big { width: 96px; height: 96px; flex-basis: 96px; font-size: 40px; }
.meta { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.ptitle { font-size: 15px; line-height: 1.25; }
.sub { color: var(--muted); font-size: 13px; }
.ean { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.stockbadge {
  min-width: 40px; text-align: center; font-weight: 800; font-size: 18px;
  background: var(--surface-2); border-radius: 10px; padding: 8px 10px;
}
.stockbadge.danger { background: var(--danger-bg); color: var(--danger); }

/* Bottom nav */
.bottomnav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
  display: flex; background: var(--surface); border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.bottomnav a {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 10px; color: var(--muted); text-decoration: none; font-size: 12px;
}
.bottomnav a.active { color: var(--accent); }
.bottomnav .ico { font-size: 22px; }

/* Scan */
.scanwrap { display: flex; flex-direction: column; gap: 14px; }
.camera {
  position: relative; width: 100%; aspect-ratio: 3/4; max-height: 56vh;
  background: #000; border-radius: var(--radius); overflow: hidden;
}
.camera.off { display: none; }
.camera video { width: 100%; height: 100%; object-fit: cover; }
.reticle {
  position: absolute; inset: 22% 12%; border: 3px solid var(--accent);
  border-radius: 12px; box-shadow: 0 0 0 100vmax rgba(0,0,0,.35);
}
.scanstatus { text-align: center; color: var(--muted); margin: 0; }
.manual { display: flex; gap: 8px; }
.manual input {
  flex: 1; background: var(--surface); border: 1px solid var(--border);
  color: var(--text); padding: 12px 14px; border-radius: var(--radius); font-size: 15px;
}
.photo-fallback { width: 100%; }

/* Résultat scan */
.result { margin-top: 4px; }
.rescard {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px; display: flex; flex-direction: column; gap: 8px; align-items: flex-start;
}
.rescard.danger { border-color: var(--danger); }
.big-stock { display: flex; align-items: baseline; gap: 8px; }
.big-stock span { font-size: 44px; font-weight: 800; }
.big-stock small { color: var(--muted); }
.stock-actions { display: flex; gap: 10px; }
.alert { color: var(--danger); font-weight: 700; margin: 0; }

/* Formulaire création */
.createform { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.createform h3 { margin: 0; }
.createform label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.createform input {
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text);
  padding: 11px 12px; border-radius: 10px; font-size: 15px;
}
.createform .row { display: flex; gap: 10px; }
.createform .row label { flex: 1; }
.createform .preview { max-width: 120px; border-radius: 10px; }
.createform .src { color: var(--muted); font-size: 12px; margin: 0; }

/* Achat / factures */
.pagetitle { font-size: 22px; margin: 4px 0 16px; }
.createform select {
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text);
  padding: 11px 12px; border-radius: 10px; font-size: 15px;
}
.createform summary { cursor: pointer; font-weight: 700; padding: 4px 0; }
.statusbadge {
  font-size: 12px; font-weight: 700; padding: 3px 10px; border-radius: 999px;
  background: var(--surface-2); color: var(--muted); text-transform: capitalize;
}
.statusbadge.brouillon { color: var(--muted); }
.statusbadge.confirme { color: var(--accent); border: 1px solid var(--accent); }
.statusbadge.paye { background: var(--accent); color: #042; }
.card a .statusbadge { margin-left: auto; }

/* Détail produit */
.detail-head { display: flex; gap: 14px; align-items: center; margin-bottom: 16px; }
.detail-head h1 { font-size: 20px; margin: 0 0 4px; }
.stockpanel {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px; display: flex; flex-direction: column; gap: 12px; align-items: flex-start; margin-bottom: 16px;
}
.stockpanel.danger { border-color: var(--danger); }
.prices { display: flex; gap: 10px; margin-bottom: 20px; }
.prices div {
  flex: 1; background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; padding: 12px; display: flex; flex-direction: column; gap: 4px;
}
.prices small { color: var(--muted); font-size: 12px; }
.prices strong { font-size: 17px; }
.marketref { color: var(--muted); font-size: 13px; margin: -8px 0 20px; }

h2 { font-size: 16px; }
.history { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 6px; }
.history li {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px;
}
.history .delta { font-weight: 800; min-width: 36px; }
.history .delta.pos { color: var(--accent); }
.history .delta.neg { color: var(--danger); }
.history .reason { font-size: 14px; }
.history .date { color: var(--muted); font-size: 12px; margin-left: auto; }
.history .note { width: 100%; color: var(--muted); font-size: 13px; }
