:root {
  --fond: #f4f6f3;
  --surface: #ffffff;
  --texte: #1d2420;
  --discret: #6b766f;
  --bord: #dfe5e0;
  --accent: #1f7a4d;
  --accent-doux: #e3f2e9;
  --danger: #b3261e;
  --coche: #9aa59e;
  --ombre: 0 1px 3px rgba(0, 0, 0, .08);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --fond: #121614;
    --surface: #1c221f;
    --texte: #e6ece8;
    --discret: #93a099;
    --bord: #2c3530;
    --accent: #4cc285;
    --accent-doux: #1f3529;
    --danger: #f2867e;
    --coche: #5d6862;
    --ombre: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--fond);
  color: var(--texte);
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }

/* En-tête ---------------------------------------------------------------- */
.entete {
  position: sticky; top: 0; z-index: 10;
  background: var(--accent);
  color: #fff;
  padding: calc(8px + env(safe-area-inset-top)) 16px 10px;
}
.entete-haut { display: flex; align-items: center; gap: 8px; max-width: 760px; margin: 0 auto; }
.entete h1 { font-size: 1.25rem; margin: 0; flex: 1; }
.sync { font-size: .7rem; opacity: .9; color: #b9f5d2; transition: color .3s; }
.sync.hors-ligne { color: #ffb4ab; }
.profil {
  background: rgba(255,255,255,.18); border: 0; color: #fff;
  border-radius: 999px; padding: 4px 12px; font-size: .9rem;
}
.recherche { max-width: 760px; margin: 8px auto 0; }
.recherche input {
  width: 100%; border: 0; border-radius: 10px; padding: 10px 14px;
  background: #fff; color: #1d2420; font-size: 1rem;
}

main { max-width: 760px; margin: 0 auto; padding: 12px 16px; }

/* Rayons du catalogue ------------------------------------------------------ */
.rayon {
  background: var(--surface); border: 1px solid var(--bord); border-radius: 12px;
  margin-bottom: 10px; box-shadow: var(--ombre); overflow: hidden;
}
.rayon > summary {
  list-style: none; display: flex; align-items: center; gap: 10px;
  padding: 12px 14px; font-weight: 600; cursor: pointer; user-select: none;
}
.rayon > summary::-webkit-details-marker { display: none; }
.rayon > summary .icone { font-size: 1.3rem; }
.rayon > summary .titre { flex: 1; }
.rayon > summary .nb {
  font-size: .8rem; font-weight: 600; background: var(--accent); color: #fff;
  border-radius: 999px; padding: 1px 8px;
}
.rayon > summary::after { content: "›"; font-size: 1.3rem; color: var(--discret); transition: transform .2s; }
.rayon[open] > summary::after { transform: rotate(90deg); }

.produits { display: flex; flex-wrap: wrap; gap: 8px; padding: 0 12px 14px; }
.produit {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--bord); background: var(--fond);
  border-radius: 999px; padding: 7px 12px; font-size: .95rem;
  transition: background .15s, border-color .15s;
}
.produit.choisi { background: var(--accent-doux); border-color: var(--accent); font-weight: 600; }
.produit .qte {
  background: var(--accent); color: #fff; border-radius: 999px;
  min-width: 22px; padding: 0 6px; font-size: .8rem; text-align: center;
}
.produit.perso { border-style: dashed; }
.produit.ajout { border-style: dashed; color: var(--accent); background: transparent; }

.titre-section { font-size: .85rem; text-transform: uppercase; letter-spacing: .04em; color: var(--discret); margin: 6px 4px 8px; }
.vide { text-align: center; color: var(--discret); padding: 40px 16px; }

/* Liste en magasin --------------------------------------------------------- */
.liste-resume { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.progression { flex: 1; height: 8px; background: var(--bord); border-radius: 999px; overflow: hidden; }
#barre { height: 100%; width: 0; background: var(--accent); transition: width .3s; }
#compte { font-size: .9rem; color: var(--discret); white-space: nowrap; }

.groupe { margin-bottom: 16px; }
.groupe h3 { display: flex; gap: 8px; align-items: center; font-size: 1rem; margin: 0 4px 6px; }
.groupe h3 small { color: var(--discret); font-weight: 400; }
.articles { background: var(--surface); border: 1px solid var(--bord); border-radius: 12px; box-shadow: var(--ombre); }
.article { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-top: 1px solid var(--bord); }
.article:first-child { border-top: 0; }
.article input[type=checkbox] { width: 24px; height: 24px; accent-color: var(--accent); flex: none; margin: 0; }
.article .infos { flex: 1; min-width: 0; }
.article .nom { font-weight: 500; overflow-wrap: anywhere; }
.article .meta { font-size: .8rem; color: var(--discret); }
.article .note {
  width: 100%; border: 0; border-bottom: 1px dashed transparent; background: transparent;
  font-size: .85rem; color: var(--discret); padding: 2px 0;
}
.article .note:focus { outline: none; border-bottom-color: var(--accent); color: var(--texte); }
.article.coche .nom { text-decoration: line-through; color: var(--coche); }
.article.coche { background: color-mix(in srgb, var(--fond) 50%, transparent); }
.stepper { display: flex; align-items: center; gap: 2px; flex: none; }
.stepper button {
  width: 32px; height: 32px; border-radius: 8px; border: 1px solid var(--bord);
  background: var(--fond); font-size: 1.1rem; line-height: 1;
}
.stepper span { min-width: 26px; text-align: center; font-weight: 600; }

.liste-actions { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
.liste-actions button, dialog button {
  border: 0; border-radius: 10px; padding: 12px; background: var(--accent); color: #fff; font-weight: 600;
}
.liste-actions button.danger { background: transparent; color: var(--danger); border: 1px solid var(--danger); }
dialog button.secondaire { background: transparent; color: var(--texte); border: 1px solid var(--bord); }

/* Onglets ------------------------------------------------------------------ */
.onglets {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 10;
  display: flex; background: var(--surface); border-top: 1px solid var(--bord);
  padding-bottom: env(safe-area-inset-bottom);
}
.onglets button {
  flex: 1; border: 0; background: none; padding: 8px 0 10px;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-size: .8rem; color: var(--discret);
}
.onglets button span { font-size: 1.35rem; }
.onglets button.actif { color: var(--accent); font-weight: 600; }
.onglets b:empty { display: none; }
.onglets b { background: var(--accent); color: #fff; border-radius: 999px; padding: 0 6px; font-size: .75rem; }

/* Dialogues ---------------------------------------------------------------- */
dialog {
  border: 0; border-radius: 16px; padding: 20px; width: min(92vw, 380px);
  background: var(--surface); color: var(--texte);
}
dialog::backdrop { background: rgba(0,0,0,.45); }
dialog h2 { margin: 0 0 8px; font-size: 1.2rem; }
dialog p { margin: 0 0 12px; color: var(--discret); font-size: .9rem; }
dialog label { display: block; font-size: .9rem; margin-bottom: 10px; }
dialog input:not([type=checkbox]), dialog select {
  display: block; width: 100%; margin-top: 4px; padding: 10px;
  border: 1px solid var(--bord); border-radius: 8px; background: var(--fond);
}
dialog label.case { display: flex; align-items: center; gap: 8px; }
dialog menu { display: flex; justify-content: flex-end; gap: 8px; margin: 16px 0 0; padding: 0; }
.erreur { color: var(--danger) !important; min-height: 1em; }

.toast {
  position: fixed; left: 50%; bottom: calc(84px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: #2b322e; color: #fff; padding: 10px 16px; border-radius: 10px; font-size: .9rem;
  max-width: calc(100vw - 32px); z-index: 20; display: flex; gap: 12px; align-items: center;
}
.toast button { background: none; border: 0; color: #8ee0b2; font-weight: 600; padding: 0; }

/* Sous-rayons ------------------------------------------------------------- */
.rayon .contenu { padding-bottom: 6px; }
.sous-titre {
  margin: 4px 14px 8px; font-size: .78rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .05em; color: var(--accent);
}
.produit .fleche { font-size: .75rem; color: var(--discret); }
.sous-entete {
  padding: 6px 12px; font-size: .75rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em;
  color: var(--accent); background: var(--accent-doux); border-top: 1px solid var(--bord);
}
.articles > .sous-entete:first-child { border-top: 0; border-radius: 12px 12px 0 0; }

/* Formats ------------------------------------------------------------------ */
#formats-liste { display: flex; flex-direction: column; gap: 6px; max-height: 50vh; overflow-y: auto; }
.format {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px;
  border: 1px solid var(--bord); border-radius: 10px; cursor: pointer;
}
.format.choisi { background: var(--accent-doux); border-color: var(--accent); font-weight: 600; cursor: default; }
.format-nom { flex: 1; }
dialog .format-ajouter, dialog .stepper button {
  width: 32px; height: 32px; padding: 0; border-radius: 8px; font-size: 1.1rem; line-height: 1;
  background: var(--fond); color: var(--texte); border: 1px solid var(--bord); font-weight: 400;
}
dialog .format-ajouter { background: var(--accent); color: #fff; border: 0; }
.formats-autre { display: flex; gap: 8px; margin-top: 12px; }
.formats-autre input { margin-top: 0 !important; }
.formats-autre button { white-space: nowrap; }

/* Historique ----------------------------------------------------------------- */
.histo summary .titre small { display: block; font-weight: 400; font-size: .8rem; color: var(--discret); }
.histo .contenu { padding: 0 12px 12px; }
.histo .articles { box-shadow: none; }
.histo-outils { display: flex; gap: 8px; margin-bottom: 8px; }
.histo-outils button {
  border: 1px solid var(--bord); background: var(--fond); border-radius: 8px; padding: 4px 10px; font-size: .85rem;
}
.histo-article { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-top: 1px solid var(--bord); }
.histo-article input { width: 20px; height: 20px; accent-color: var(--accent); margin: 0; flex: none; }
.histo-article i { color: var(--discret); }
.liste-actions button:disabled { opacity: .5; cursor: default; }

/* Impression / PDF --------------------------------------------------------- */
#impression { display: none; }
@media print {
  @page { margin: 12mm; }
  :root { color-scheme: light; }
  body { background: #fff; color: #000; padding: 0; margin: 0; }
  body > *:not(#impression) { display: none !important; }
  #impression { display: block; columns: 2; column-gap: 10mm; font-size: 11pt; }
  #impression h1 { font-size: 16pt; margin: 0; column-span: all; }
  #impression .imp-date { margin: 2pt 0 8pt; color: #444; column-span: all; }
  #impression h2 { font-size: 12pt; margin: 8pt 0 3pt; padding-bottom: 2pt; border-bottom: 1px solid #000; break-after: avoid; }
  #impression h3 { font-size: 9pt; font-weight: 600; text-transform: uppercase; color: #444; margin: 5pt 0 1pt; break-after: avoid; }
  .imp-article { display: flex; align-items: flex-start; gap: 6pt; padding: 2.5pt 0; break-inside: avoid; }
  .imp-case { flex: none; width: 11pt; height: 11pt; border: 1.2pt solid #000; border-radius: 2pt; margin-top: 1pt; }
  .imp-qte { flex: none; min-width: 20pt; font-weight: 700; }
  .imp-nom { overflow-wrap: anywhere; }
  .imp-nom i { display: block; font-size: 9.5pt; color: #333; }
}

/* Favoris ------------------------------------------------------------------ */
.favoris {
  background: var(--surface); border: 1px solid var(--bord); border-radius: 12px;
  box-shadow: var(--ombre); padding: 10px 12px 4px; margin-bottom: 14px;
}
.favoris-entete { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.favoris-entete .titre-section { flex: 1; margin: 0; }
.favoris-entete small { background: var(--accent); color: #fff; border-radius: 999px; padding: 0 7px; font-size: .75rem; }
.petit-bouton {
  border: 1px solid var(--bord); background: var(--fond); border-radius: 8px;
  padding: 5px 10px; font-size: .85rem; white-space: nowrap;
}
.fav-rayon { margin-bottom: 8px; }
.fav-rayon-nom { font-size: .78rem; font-weight: 700; color: var(--discret); margin: 0 2px 5px; }
.favoris .produits { padding: 0; }
.fav-vide { color: var(--discret); font-size: .9rem; margin: 4px 2px 10px; }
.fav-regle { font-size: .78rem; color: var(--discret); margin: -2px 2px 8px; }

/* Quantités ----------------------------------------------------------------- */
.produit.puce-qte { padding: 3px; gap: 4px; }
.puce-qte .puce-nom { padding: 0 2px; }
.puce-btn {
  width: 28px; height: 28px; border: 0; border-radius: 999px; padding: 0;
  background: var(--accent); color: #fff; font-size: 1.05rem; line-height: 1; flex: none;
}
.unite-liste { font-size: .8rem; font-weight: 400; color: var(--discret); }

/* Menu produit (clic droit / appui long) -------------------------------------- */
.menu-actions { display: flex; flex-direction: column; gap: 8px; }
#menu-info:empty { display: none; }
.produit .etoile { color: #e0a800; font-size: .85rem; margin-right: 2px; }
.produit, .article .nom { -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; }

/* Rayons : nombre de produits ------------------------------------------------ */
.nb-produits { font-weight: 400; font-style: italic; font-size: .78rem; color: var(--discret); }

/* Réglages ------------------------------------------------------------------- */
.carte {
  background: var(--surface); border: 1px solid var(--bord); border-radius: 12px;
  box-shadow: var(--ombre); padding: 14px; margin-bottom: 14px;
}
.carte h2 { font-size: 1.05rem; margin: 0 0 6px; }
.carte h3 { font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; color: var(--accent); margin: 16px 0 8px; }
.carte h3:first-child { margin-top: 4px; }
.carte .aide { color: var(--discret); font-size: .85rem; margin: 0 0 10px; }
.carte input {
  display: block; width: 100%; margin-bottom: 8px; padding: 10px;
  border: 1px solid var(--bord); border-radius: 8px; background: var(--fond);
}
.carte button[type=submit], #btn-sauvegarde {
  border: 0; border-radius: 10px; padding: 11px 14px; background: var(--accent); color: #fff; font-weight: 600;
}
#btn-sauvegarde { width: 100%; margin-bottom: 8px; }
.ligne-form { display: flex; gap: 8px; }
.ligne-form input { margin-bottom: 0; }
.message { font-size: .85rem; margin: 0 0 8px; min-height: 1em; }
.message.succes { color: var(--accent); }
.message.erreur { color: var(--danger); }
.tuiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 8px; }
.tuile { background: var(--fond); border-radius: 10px; padding: 10px; display: flex; flex-direction: column; gap: 2px; }
.tuile b { font-size: 1.2rem; color: var(--texte); }
.tuile span { font-size: .78rem; color: var(--discret); }
.classement { margin: 0; padding-left: 22px; }
.classement li { padding: 4px 0; border-bottom: 1px solid var(--bord); }
.classement li span { display: inline-block; max-width: 75%; }
.classement li b { float: right; font-weight: 600; color: var(--discret); }
.barre-ligne { display: grid; grid-template-columns: minmax(0, 1.4fr) 1fr 44px; gap: 8px; align-items: center; margin-bottom: 6px; font-size: .88rem; }
.barre-ligne span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.barre-fond { height: 8px; background: var(--fond); border-radius: 999px; overflow: hidden; }
.barre-fond div { height: 100%; background: var(--accent); }
.barre-ligne b { text-align: right; font-weight: 600; color: var(--discret); }
.onglets button { font-size: .72rem; }

/* Unités indicatives et choix de l'unité --------------------------------------- */
.unite-indic {
  font-size: .7rem; font-weight: 600; color: var(--discret);
  border: 1px solid var(--bord); border-radius: 4px; padding: 0 4px; margin-left: 2px;
}
.menu-label { font-size: .85rem; margin: 4px 0 6px !important; }
.menu-unites { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-bottom: 14px; }
dialog .menu-unites button {
  padding: 9px 4px; background: var(--fond); color: var(--texte); border: 1px solid var(--bord); font-weight: 500;
}
dialog .menu-unites button.actif { background: var(--accent); color: #fff; border-color: var(--accent); font-weight: 700; }

/* Nombre de paquets (2 × 500 g) ---------------------------------------------- */
.paquets { display: flex; align-items: center; gap: 6px; font-size: .8rem; color: var(--discret); margin: 3px 0 1px; }
.paquets button {
  width: 24px; height: 24px; padding: 0; border-radius: 6px; border: 1px solid var(--bord);
  background: var(--fond); font-size: .95rem; line-height: 1;
}
.paquets b { color: var(--texte); min-width: 14px; text-align: center; }
.puce-qte .puce-ligne { display: inline-flex; align-items: center; gap: 4px; }
.produit.puce-qte.avec-paquets { flex-direction: column; align-items: stretch; border-radius: 16px; gap: 2px; }
.puce-paquets {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  font-size: .75rem; font-weight: 400; color: var(--discret); padding-bottom: 2px;
}
.puce-paquets button {
  width: 22px; height: 22px; padding: 0; border-radius: 6px; border: 1px solid var(--bord);
  background: var(--surface); color: var(--texte); font-size: .9rem; line-height: 1;
}
.puce-paquets b { color: var(--texte); }
