:root {
  --green: #16a34a;
  --green-d: #15803d;
  --bg: #f4f5f7;
  --card: #ffffff;
  --ink: #1f2430;
  --muted: #7a8292;
  --line: #e6e8ec;
  --red: #dc2626;
  --amber: #d97706;
  --radius: 14px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
body {
  margin: 0; font-family: -apple-system, system-ui, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--ink);
  padding-bottom: 76px;
}
h1 { font-size: 1.1rem; margin: 0; }
h2 { font-size: 1.05rem; margin: 4px 0 12px; }

.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  background: var(--green); color: #fff; padding: 14px 16px;
  box-shadow: 0 2px 8px rgba(0,0,0,.12);
}
.month-total { font-size: .9rem; font-weight: 600; opacity: .95; }

main { padding: 16px; max-width: 680px; margin: 0 auto; }
.tab { display: none; }
.tab.active { display: block; }

/* ---------- cards / forms ---------- */
.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px; margin-bottom: 14px;
}
label { display: block; font-size: .78rem; color: var(--muted); font-weight: 600; margin-bottom: 10px; }
input, select {
  width: 100%; margin-top: 4px; padding: 11px 12px; font-size: 1rem;
  border: 1px solid var(--line); border-radius: 10px; background: #fff; color: var(--ink);
}
input:focus { outline: none; border-color: var(--green); }
.row { display: flex; gap: 10px; }
.row label { flex: 1; }
.check-inline { display: flex; align-items: center; gap: 8px; color: var(--ink); font-size: .95rem; }
.check-inline input { width: auto; margin: 0; }

.btn {
  border: none; border-radius: 10px; padding: 11px 16px; font-size: .95rem;
  font-weight: 600; background: #eceef1; color: var(--ink); cursor: pointer;
}
.btn.primary { background: var(--green); color: #fff; }
.btn.primary:active { background: var(--green-d); }
.btn.ghost { background: transparent; border: 1px solid var(--line); color: var(--muted); }
.btn.full { width: 100%; margin-top: 10px; }
.form-actions { display: flex; gap: 10px; margin-top: 4px; }
.form-actions .btn { flex: 1; }

/* ---------- scanner ---------- */
.scan-box { text-align: center; }
#reader { border-radius: var(--radius); overflow: hidden; margin-bottom: 12px; }
#reader:empty { display: none; }
.scan-actions { display: flex; gap: 10px; justify-content: center; margin-bottom: 12px; }
.manual-code { display: flex; gap: 8px; }
.manual-code input { margin: 0; }
.manual-code .btn { white-space: nowrap; }

.prod-head { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.prod-img { width: 64px; height: 64px; object-fit: contain; border-radius: 10px; background: #fafafa; border: 1px solid var(--line); }
.prod-meta { display: flex; flex-direction: column; gap: 4px; }
.pill { align-self: flex-start; font-size: .68rem; font-weight: 700; text-transform: uppercase;
  background: #e8f6ee; color: var(--green-d); padding: 3px 8px; border-radius: 20px; }
.pill.manual { background: #fff4e5; color: var(--amber); }

/* ---------- lists ---------- */
.list { display: flex; flex-direction: column; gap: 10px; }
.item {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 14px; display: flex; align-items: center; gap: 12px;
}
.item img { width: 46px; height: 46px; object-fit: contain; border-radius: 8px; background:#fafafa; border:1px solid var(--line); flex:none; }
.item .grow { flex: 1; min-width: 0; }
.item .name { font-weight: 600; font-size: .98rem; }
.item .sub { font-size: .78rem; color: var(--muted); margin-top: 2px; }
.badge { font-size: .72rem; font-weight: 700; padding: 2px 8px; border-radius: 20px; background:#eef0f3; color:var(--muted); }
.badge.soon { background:#fff4e5; color: var(--amber); }
.badge.expired { background:#fde8e8; color: var(--red); }
.qty-ctrl { display: flex; align-items: center; gap: 8px; }
.qty-ctrl button { width: 32px; height: 32px; border-radius: 50%; border:1px solid var(--line); background:#fff; font-size:1.1rem; line-height:1; cursor:pointer; }
.qty-ctrl .q { min-width: 26px; text-align:center; font-weight:700; }
.icon-btn { background:none; border:none; font-size:1.1rem; cursor:pointer; color:var(--muted); padding:4px; }

.check-item .name.done { text-decoration: line-through; color: var(--muted); }

/* ---------- stats ---------- */
.stats-card canvas { margin-top: 10px; }
.big-total { font-size: 2rem; font-weight: 800; color: var(--green-d); text-align:center; }
.big-total small { font-size: .8rem; color: var(--muted); font-weight: 600; }

.add-row { display: flex; gap: 8px; margin-bottom: 14px; }
.add-row input { margin: 0; }
.add-row .btn { font-size: 1.3rem; padding: 0 18px; }

/* ---------- tabbar ---------- */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
  display: flex; background: #fff; border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbtn {
  flex: 1; border: none; background: none; padding: 9px 0; font-size: 1.3rem;
  color: var(--muted); display: flex; flex-direction: column; align-items: center; gap: 2px; cursor: pointer;
}
.tabbtn span { font-size: .66rem; font-weight: 600; }
.tabbtn.active { color: var(--green); }

/* ---------- misc ---------- */
.muted { color: var(--muted); }
.small { font-size: .78rem; }
.center { text-align: center; }
.hidden { display: none !important; }
.toast {
  position: fixed; bottom: 86px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: #1f2430; color: #fff; padding: 11px 18px; border-radius: 24px; font-size: .9rem;
  opacity: 0; pointer-events: none; transition: all .25s; z-index: 50; max-width: 90%;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.err { background: var(--red); }

.topbar .logout { color:#fff; text-decoration:none; font-size:1.3rem; opacity:.9; padding:0 2px 0 10px; }
.topbar .logout:active { opacity:.6; }
.month-total { margin-left:auto; }

/* --- Affichage du flux caméra (html5-qrcode) --- */
#reader { width:100%; min-height:240px; background:#000; position:relative; }
#reader:empty { min-height:0; background:transparent; }
#reader video {
  width:100% !important; height:auto !important; display:block !important;
  border-radius:var(--radius); object-fit:cover;
}
#reader canvas { display:none; }
#reader img[alt="Info icon"], #reader__dashboard_section_csr span { font-size:.8rem; }
#reader__scan_region { min-height:220px; display:flex; align-items:center; justify-content:center; }
#reader__scan_region img { display:none; }
