/* ============================================================
   Courses – styles (mobile d'abord, thème clair/sombre auto)
   ============================================================ */
:root {
  --bg: #f4f6f5;
  --surface: #ffffff;
  --surface-2: #eef1ef;
  --text: #17201b;
  --muted: #66736b;
  --border: #dde3df;
  --primary: #16a34a;
  --primary-strong: #15803d;
  --primary-soft: #dcfce7;
  --danger: #dc2626;
  --warn: #d97706;
  --shadow: 0 1px 2px rgb(0 0 0 / .06), 0 4px 16px rgb(0 0 0 / .06);
  --radius: 14px;
  --tabbar-h: 64px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1411;
    --surface: #18201b;
    --surface-2: #212b25;
    --text: #e7ede9;
    --muted: #93a198;
    --border: #2c3831;
    --primary: #22c55e;
    --primary-strong: #16a34a;
    --primary-soft: #14301f;
    --danger: #f87171;
    --shadow: 0 1px 2px rgb(0 0 0 / .4);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  padding-bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 80px);
  -webkit-tap-highlight-color: transparent;
}
body.no-scroll { overflow: hidden; }
[hidden] { display: none !important; }
a { color: var(--primary); }
h1, h2, h3 { margin: 0 0 .5em; line-height: 1.2; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.center { text-align: center; }
.spacer { flex: 1; }

/* ---------- Boutons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4em;
  min-height: 44px; padding: 0 16px;
  border: 1px solid var(--border); border-radius: 12px;
  background: var(--surface); color: var(--text);
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
}
.btn:active { transform: scale(.98); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-strong); }
.btn-danger { color: var(--danger); }
.btn-block { display: flex; width: 100%; margin-top: 10px; }
.btn-sm { min-height: 36px; padding: 0 12px; font-size: .9rem; }
.icon-btn {
  display: inline-grid; place-items: center; flex: none;
  width: 44px; height: 44px; border: 0; border-radius: 12px;
  background: var(--surface-2); color: var(--text); font-size: 1.3rem; cursor: pointer;
}
.icon-btn.active { background: var(--primary); color: #fff; }
.link-btn { background: none; border: 0; color: var(--primary); padding: 8px 0; cursor: pointer; font: inherit; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 12px; border-radius: 999px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit; font-size: .9rem; cursor: pointer;
}

/* ---------- Formulaires ---------- */
input, select, textarea {
  width: 100%; min-height: 44px; padding: 10px 12px;
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface); color: var(--text); font: inherit;
}
input:focus, select:focus { outline: 2px solid var(--primary); outline-offset: -1px; border-color: transparent; }
input[type="checkbox"] { width: 20px; min-height: 20px; height: 20px; accent-color: var(--primary); flex: none; }
.form label, .sheet label { display: block; margin-bottom: 12px; font-size: .9rem; color: var(--muted); }
.form label input, .form label select, .sheet label input, .sheet label select { margin-top: 4px; color: var(--text); font-size: 1rem; }
label.check { display: flex; align-items: center; gap: 10px; color: var(--text); font-size: 1rem; }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; min-width: 0; }
.hint { margin: -6px 0 12px; padding: 8px 10px; border-radius: 10px; background: var(--primary-soft); color: var(--primary-strong); }
@media (prefers-color-scheme: dark) { .hint { color: var(--primary); } }
.store-badge {
  display: inline-block; margin-top: 2px; padding: 1px 8px; border-radius: 999px;
  background: var(--surface-2); color: var(--muted); font-size: .75rem; font-weight: 600;
}
.store-filter { display: flex; gap: 6px; overflow-x: auto; margin-bottom: 4px; padding-bottom: 4px; scrollbar-width: none; }
.store-filter .chip { flex: none; }
.store-filter .chip.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.shop-other { margin: 18px auto 0; max-width: 720px; padding: 0 12px; }
.shop-other summary { cursor: pointer; padding: 10px 4px; color: var(--muted); font-weight: 600; font-size: .9rem; }
.shop-other .shop-item { opacity: .75; }
/* Fiche agrandie en mode courses */
.item-card { text-align: center; }
.card-image { display: grid; place-items: center; height: 150px; margin-bottom: 10px; }
.card-image img { max-height: 150px; max-width: 70%; border-radius: 14px; background: #fff; object-fit: contain; }
.card-icon { font-size: 5rem; line-height: 1; }
.card-name { font-size: 1.8rem; margin: 0 0 4px; overflow-wrap: anywhere; }
.card-brand { margin: 0 0 12px; font-size: 1.05rem; }
.card-qty-label { font-size: .8rem; text-transform: uppercase; letter-spacing: .08em; }
.card-qty {
  margin: 2px auto 12px; padding: 6px 24px; display: inline-block; min-width: 120px;
  border-radius: 20px; background: var(--primary-soft); color: var(--primary-strong);
  font-size: 3.5rem; font-weight: 800; line-height: 1.15; overflow-wrap: anywhere;
}
@media (prefers-color-scheme: dark) { .card-qty { color: var(--primary); } }
.card-note { margin: 0 0 8px; font-size: 1.15rem; font-style: italic; }
.card-meta { margin: 0 0 16px; }
.card-take { display: flex; width: 100%; min-height: 64px; font-size: 1.4rem; border-radius: 16px; }
.stepper { display: flex; gap: 8px; align-items: center; margin-top: 4px; }
.stepper input { flex: 1; margin-top: 0 !important; text-align: center; font-size: 1.2rem !important; font-weight: 700; }
.qty-chips { display: flex; flex-wrap: wrap; gap: 6px; margin: -4px 0 14px; }
.input-with-btn { display: flex; gap: 8px; align-items: center; margin-top: 4px; }
.input-with-btn input { flex: 1; margin-top: 0 !important; }
#barcode-status { margin: -6px 0 12px; }
.code-input { text-transform: uppercase; letter-spacing: .15em; font-family: ui-monospace, monospace; }

/* ---------- Pages connexion ---------- */
.auth-page { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.auth-card {
  width: 100%; max-width: 400px; padding: 28px 22px;
  background: var(--surface); border-radius: 20px; box-shadow: var(--shadow);
}
.brand { font-size: 1.4rem; font-weight: 800; color: var(--primary); margin-bottom: 18px; }
.alert { padding: 10px 12px; border-radius: 10px; margin-bottom: 14px; font-size: .95rem; }
.alert-error { background: color-mix(in srgb, var(--danger) 14%, transparent); color: var(--danger); }
.alert-info { background: var(--primary-soft); color: var(--primary-strong); }
.divider { display: flex; align-items: center; gap: 10px; margin: 22px 0; color: var(--muted); }
.divider::before, .divider::after { content: ""; flex: 1; border-top: 1px solid var(--border); }

/* ---------- Structure appli ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 10px;
  padding: calc(10px + env(safe-area-inset-top, 0px)) 16px 10px;
  background: var(--primary); color: #fff;
}
.topbar h1 { flex: 1; margin: 0; font-size: 1.15rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sync-pill {
  border: 0; border-radius: 999px; padding: 4px 10px; font-size: .78rem; font-weight: 600;
  background: rgb(255 255 255 / .2); color: #fff; cursor: pointer;
}
.sync-pill.offline { background: #fef3c7; color: #92400e; }
.sync-pill.pending { background: rgb(255 255 255 / .35); }
main { max-width: 720px; margin: 0 auto; padding: 12px 16px; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; height: calc(var(--tabbar-h) + var(--safe-bottom)); padding-bottom: var(--safe-bottom);
  background: var(--surface); border-top: 1px solid var(--border);
}
.tabbar a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); text-decoration: none; font-size: .75rem; font-weight: 600;
}
.tabbar a span { font-size: 1.3rem; filter: grayscale(1); opacity: .7; }
.tabbar a.active { color: var(--primary); }
.tabbar a.active span { filter: none; opacity: 1; }

/* ---------- Barre d'ajout + suggestions ---------- */
.add-bar { position: relative; display: flex; gap: 8px; margin-bottom: 10px; }
.add-bar input { flex: 1; }
.suggestions {
  position: absolute; top: 100%; left: 0; right: 0; z-index: 20;
  margin: 4px 0 0; padding: 4px; list-style: none;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow);
}
.suggestions li { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: 8px; cursor: pointer; }
.suggestions li:hover { background: var(--surface-2); }
.suggestions li.new { color: var(--primary); font-weight: 600; }
.suggestions li > span:nth-child(2) { flex: 1; }

.list-actions, .filter-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.section-head { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 8px; margin: 6px 0; }
.section-head h2 { margin: 0; }

/* ---------- Lignes ---------- */
.group-title { margin: 16px 4px 6px; font-size: .85rem; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.row-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px; margin-bottom: 6px;
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  cursor: pointer; transition: opacity .25s, transform .25s;
}
.row-item.leaving { opacity: 0; transform: translateX(40px); }
.row-main { flex: 1; min-width: 0; }
.row-title { font-weight: 600; }
.row-title small { font-weight: 400; }
.row-note { font-size: .85rem; color: var(--muted); }
.row-by { font-size: .75rem; color: var(--muted); font-style: italic; }
.qty {
  display: inline-block; padding: 1px 8px; border-radius: 999px;
  background: var(--primary-soft); color: var(--primary-strong); font-size: .8rem; font-weight: 700;
}
@media (prefers-color-scheme: dark) { .qty { color: var(--primary); } }
.thumb { width: 40px; height: 40px; flex: none; border-radius: 10px; object-fit: contain; background: #fff; }
.thumb-icon { display: grid; place-items: center; background: var(--surface-2); font-size: 1.3rem; }
.check-btn {
  width: 28px; height: 28px; flex: none; border-radius: 50%;
  border: 2px solid var(--primary); background: transparent; cursor: pointer; padding: 0;
}
.check-btn:active, .leaving .check-btn { background: var(--primary); }
.badge { font-size: .8rem; }
.on-list { font-size: .8rem; color: var(--primary); font-weight: 600; white-space: nowrap; }
.add-btn { background: var(--primary-soft); color: var(--primary); }

.empty { text-align: center; padding: 40px 20px; }
.empty-icon { font-size: 3rem; }

.fab {
  position: fixed; z-index: 9; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 14px);
  padding: 14px 26px; border: 0; border-radius: 999px;
  background: var(--primary); color: #fff; font: inherit; font-weight: 700; font-size: 1.05rem;
  box-shadow: 0 6px 20px rgb(22 163 74 / .45); cursor: pointer; white-space: nowrap;
}

/* ---------- Carte / famille ---------- */
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 12px; }
.invite { display: flex; align-items: center; gap: 10px; margin: 8px 0; }
.invite code {
  flex: 1; padding: 10px; border-radius: 10px; background: var(--surface-2);
  font-size: 1.5rem; font-weight: 700; letter-spacing: .2em; text-align: center;
}
.members { list-style: none; margin: 0; padding: 0; }
.members li { padding: 6px 0; border-bottom: 1px solid var(--border); }
.members li:last-child { border: 0; }

/* ---------- Dialogues (feuilles du bas) ---------- */
dialog.sheet {
  width: 100%; max-width: 560px; max-height: 92vh; margin: auto auto 0;
  padding: 20px 16px calc(16px + var(--safe-bottom));
  border: 0; border-radius: 20px 20px 0 0;
  background: var(--surface); color: var(--text); overflow: auto;
}
@media (min-width: 600px) { dialog.sheet { margin: auto; border-radius: 20px; } }
dialog.sheet::backdrop { background: rgb(0 0 0 / .45); }
dialog[open] { animation: slide-up .2s ease-out; }
@keyframes slide-up { from { transform: translateY(30px); opacity: 0; } }
.sheet-actions { display: flex; gap: 8px; align-items: center; margin-top: 16px; flex-wrap: wrap; }
.product-image { text-align: center; margin-bottom: 10px; }
.product-image img { max-height: 110px; max-width: 60%; border-radius: 10px; background: #fff; }
.check-list label.check { padding: 10px 0; border-bottom: 1px solid var(--border); margin: 0; }
.pick-list { display: grid; gap: 8px; margin-bottom: 8px; }
.pick-item {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  padding: 14px; border: 1px solid var(--border); border-radius: 12px;
  background: var(--surface-2); color: var(--text); font: inherit; font-weight: 600; cursor: pointer; text-align: left;
}

/* Scanner */
.sheet-dark { background: #111 !important; color: #fff !important; }
.scan-box { position: relative; aspect-ratio: 4 / 3; border-radius: 14px; overflow: hidden; background: #000; margin-bottom: 12px; }
.scan-box video { width: 100%; height: 100%; object-fit: cover; }
.scan-frame {
  position: absolute; inset: 30% 12%; border: 3px solid rgb(255 255 255 / .85); border-radius: 12px;
  box-shadow: 0 0 0 999px rgb(0 0 0 / .35);
}
.scan-frame::after {
  content: ""; position: absolute; left: 6%; right: 6%; top: 50%; height: 2px; background: #ef4444;
  animation: scanline 1.6s ease-in-out infinite alternate;
}
@keyframes scanline { from { transform: translateY(-30px); } to { transform: translateY(30px); } }
.scan-msg { position: absolute; left: 0; right: 0; bottom: 8px; margin: 0; text-align: center; font-size: .9rem; text-shadow: 0 1px 3px #000; }
.sheet-dark input { background: #222; color: #fff; border-color: #333; }
.sheet-dark .btn:not(.btn-primary) { background: #222; color: #fff; border-color: #333; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; z-index: 100; left: 16px; right: 16px; max-width: 520px; margin: 0 auto;
  bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 76px);
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px; border-radius: 12px; background: #1f2937; color: #fff;
  box-shadow: 0 8px 24px rgb(0 0 0 / .3); font-size: .95rem;
}
.toast span { flex: 1; }
.toast button { border: 0; background: none; color: #4ade80; font: inherit; font-weight: 700; cursor: pointer; padding: 4px; }

/* ---------- Mode courses ---------- */
.shopping {
  position: fixed; inset: 0; z-index: 50; overflow-y: auto;
  background: var(--bg);
  padding-bottom: calc(90px + var(--safe-bottom));
}
body.no-scroll .toast { bottom: calc(90px + var(--safe-bottom)); }
.shopping-head {
  position: sticky; top: 0; z-index: 2;
  display: flex; align-items: center; gap: 8px;
  padding: calc(10px + env(safe-area-inset-top, 0px)) 12px 10px;
  background: var(--primary); color: #fff;
}
.shopping-head .icon-btn { background: rgb(255 255 255 / .18); color: #fff; }
.shopping-head .icon-btn.active { background: #fff; color: var(--primary); }
.shop-store {
  flex: 1; min-width: 0; border: 0; background: none; color: #fff;
  font: inherit; font-size: 1.1rem; font-weight: 700; cursor: pointer;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.shop-progress { height: 5px; background: var(--surface-2); }
.shop-progress div { height: 100%; background: var(--primary); transition: width .3s; }
.shop-list { list-style: none; margin: 0 auto; padding: 4px 12px; max-width: 720px; }
.shop-cat { margin: 14px 4px 4px; font-size: .8rem; font-weight: 700; color: var(--muted); text-transform: uppercase; }
.shop-item {
  display: flex; align-items: center; gap: 14px;
  min-height: 60px; padding: 10px 14px; margin-bottom: 6px;
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  font-size: 1.1rem; cursor: pointer; user-select: none;
  transition: opacity .22s, transform .22s;
}
.shop-item.leaving { opacity: 0; transform: translateX(60px) scale(.96); }
.shop-item .check-btn { width: 30px; height: 30px; }
.shop-name { flex: 1; min-width: 0; }
.shop-name .row-note { display: block; }
.reordering .shop-item { cursor: default; }
.reordering .shop-item .check-btn { opacity: .25; }
.reordering .shop-cat { opacity: .4; }
.drag-handle {
  display: grid; place-items: center; width: 44px; height: 44px; margin: -8px -8px -8px 0;
  font-size: 1.5rem; color: var(--muted); cursor: grab; touch-action: none;
}
.shop-item.dragging { outline: 2px solid var(--primary); box-shadow: 0 10px 24px rgb(0 0 0 / .2); position: relative; z-index: 3; }
.shop-foot {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 2;
  display: flex; gap: 8px; padding: 12px 12px calc(12px + var(--safe-bottom));
  background: var(--surface); border-top: 1px solid var(--border);
}
.shop-foot .btn-primary { flex: 1; }

/* Code-barres ajouté depuis la fenêtre de quantité */
.barcode-box { margin-bottom: 12px; padding: 10px 12px 2px; border: 1px dashed var(--border); border-radius: 12px; }
.found-card { display: flex; align-items: center; gap: 12px; margin: -4px 0 10px; padding: 8px; border-radius: 10px; background: var(--surface-2); }
.found-card img { width: 52px; height: 52px; object-fit: contain; border-radius: 8px; background: #fff; flex: none; }
.found-card img[src=""] { display: none; }
#qty-barcode-status { margin: -6px 0 10px; }

/* ---------- Onglet Liste : une carte par magasin ---------- */
/* minmax(0,1fr) : sans cela la colonne se dimensionne sur l'aperçu (texte non coupé)
   et toute la page devient plus large que l'écran. */
.store-cards { display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; }
.store-card {
  display: flex; align-items: center; gap: 14px; width: 100%;
  padding: 16px; border: 0; border-radius: var(--radius); box-shadow: var(--shadow);
  background: var(--surface); color: var(--text); font: inherit; text-align: left; cursor: pointer;
}
.store-card .thumb-icon { width: 48px; height: 48px; font-size: 1.6rem; }
.store-card-main { flex: 1; min-width: 0; }
.store-card-name { font-size: 1.1rem; font-weight: 700; }
.store-card-preview { display: block; }
.store-card-preview { font-size: .85rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.store-card-count {
  flex: none; min-width: 36px; padding: 4px 10px; border-radius: 999px; text-align: center;
  background: var(--primary); color: #fff; font-weight: 800;
}
.store-card .in-progress { color: var(--primary); font-size: .8rem; font-weight: 700; }
.store-card-none .thumb-icon { filter: grayscale(1); }

/* ---------- Onglet Produits ---------- */
.add-target {
  display: flex; align-items: center; gap: 8px; margin-bottom: 10px; padding: 8px 8px 8px 14px;
  border-radius: 12px; background: var(--primary); color: #fff; font-weight: 600;
}
.add-target span { flex: 1; min-width: 0; }
.add-target .btn { background: rgb(255 255 255 / .2); border-color: transparent; color: #fff; }
.add-target .icon-btn { background: transparent; color: #fff; }
.edit-btn { background: transparent; color: var(--muted); font-size: 1.1rem; }
.on-list-store { display: block; font-size: .75rem; color: var(--primary); font-weight: 600; }
#products-hint { margin: 0 4px 4px; }

/* ---------- Fiche article : quantité modifiable + actions ---------- */
.card-qty-row { display: flex; align-items: center; justify-content: center; gap: 14px; margin-bottom: 12px; }
.card-qty-row .card-qty { margin: 0; border: 0; font-family: inherit; cursor: pointer; }
.card-step { width: 56px; height: 56px; border-radius: 50%; font-size: 1.8rem; }
.card-actions { display: flex; gap: 8px; margin-top: 10px; }
.card-actions .btn { flex: 1; }

/* Photo d'un produit prise avec l'appareil */
.photo-actions { display: flex; gap: 8px; justify-content: center; margin-bottom: 12px; }
#photo-status { margin: -6px 0 12px; }

/* ---------- Historique des courses ---------- */
.history { display: grid; gap: 12px; }
.history-day { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px; }
.history-date { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin-bottom: 8px; }
.history-date h3 { margin: 0; font-size: 1.05rem; text-transform: capitalize; }
.history-store { margin-top: 10px; }
.history-store-name { font-size: .85rem; font-weight: 700; color: var(--muted); text-transform: uppercase; }
.history-items { list-style: none; margin: 4px 0 0; padding: 0; }
.history-items li { display: flex; gap: 8px; align-items: baseline; padding: 3px 0; border-bottom: 1px solid var(--border); }
.history-items li:last-child { border: 0; }
.history-items .who { font-size: .75rem; color: var(--muted); }
