:root {
  --bg: #f4f6f3;
  --card: #ffffff;
  --text: #1c2420;
  --muted: #6b7670;
  --line: #e3e8e4;
  --accent: #1f8a5b;
  --accent-soft: #e2f3ea;
  --danger: #c0392b;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 2px 8px rgba(0,0,0,.04);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121614;
    --card: #1c211e;
    --text: #e8ece9;
    --muted: #97a39c;
    --line: #2b322e;
    --accent: #3cbf85;
    --accent-soft: #1d3329;
    --danger: #e0685b;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  max-width: 640px; margin-inline: auto;
  padding: 0 16px calc(40px + env(safe-area-inset-bottom));
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; -webkit-tap-highlight-color: transparent; }

/* ----- Connexion ----- */
.login { min-height: 90vh; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; }
.login h1 { margin: 12px 0 4px; }
.login p { color: var(--muted); margin: 0 0 24px; }
.login form { width: 100%; max-width: 320px; display: grid; gap: 10px; }
.login input, .login button { padding: 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); }
.login button { background: var(--accent); color: #fff; border: 0; font-weight: 600; }
.error { color: var(--danger) !important; margin-top: 8px !important; }

/* ----- En-tête ----- */
.top {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 8px;
  padding: calc(10px + env(safe-area-inset-top)) 0 10px; background: var(--bg);
}
.top h1 { font-size: 22px; margin: 0; flex: 1; }
.chip { border: 1px solid var(--line); background: var(--card); border-radius: 99px; padding: 5px 12px; font-size: 14px; max-width: 40vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.icon-btn { border: 0; background: transparent; font-size: 24px; width: 40px; height: 40px; border-radius: 50%; }
.icon-btn:hover { background: var(--line); }
.menu {
  position: absolute; right: 0; top: 100%; background: var(--card); border: 1px solid var(--line);
  border-radius: 12px; box-shadow: 0 8px 24px rgba(0,0,0,.15); overflow: hidden; min-width: 260px;
}
.menu button, .menu a { display: block; width: 100%; text-align: left; padding: 12px 16px; border: 0; background: none; color: inherit; text-decoration: none; }
.menu button:hover, .menu a:hover { background: var(--accent-soft); }

/* ----- Ajout ----- */
.add { background: var(--card); border-radius: 16px; padding: 12px; box-shadow: var(--shadow); margin-bottom: 16px; display: grid; gap: 10px; }
.zone { border: 1px solid var(--line); border-radius: 12px; padding: 8px 10px 10px; margin: 0; min-width: 0; }
.zone legend { font-size: 13px; font-weight: 700; color: var(--accent); padding: 0 6px; text-transform: uppercase; letter-spacing: .03em; }
.zone legend small { font-weight: 400; color: var(--muted); text-transform: none; letter-spacing: 0; }
.row { display: flex; gap: 6px; }
.row input, #desc { min-width: 0; padding: 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); }
#name { flex: 1; }
.qty { width: 80px; }
#desc { display: block; width: 100%; margin-top: 6px; resize: vertical; font: inherit; font-size: 15px; color: inherit; }
.add-btn { width: 100%; padding: 13px; border: 0; border-radius: 12px; background: var(--accent); color: #fff; font-size: 17px; font-weight: 600; }
.suggest { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.suggest:not(:empty) { margin-top: 10px; }
.suggest small { color: var(--muted); width: 100%; }
.sug { border: 1px solid var(--line); background: var(--bg); border-radius: 99px; padding: 5px 11px; font-size: 14px; }
.sug:hover { border-color: var(--accent); }
.cats { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
.cats::-webkit-scrollbar { display: none; }
.cat { flex: none; border: 1px solid var(--line); background: var(--bg); border-radius: 99px; padding: 5px 10px; font-size: 14px; white-space: nowrap; }
.cat span { margin-left: 5px; }
.cat.on { background: var(--accent); border-color: var(--accent); color: #fff; }
body.shop .add { display: none; }
.cat.new { border-style: dashed; color: var(--muted); }
.filter { display: flex; gap: 6px; overflow-x: auto; align-items: center; margin-bottom: 14px; scrollbar-width: none; }
.filter::-webkit-scrollbar { display: none; }
.filter small { color: var(--muted); flex: none; }
.filter .cat { background: var(--card); }
.filter .cat.on { background: var(--accent); }
.filter .cat span { margin-left: 4px; opacity: .8; }
.mg { margin-left: 8px; font-size: 13px; color: var(--muted); border: 1px solid var(--line); border-radius: 6px; padding: 0 6px; white-space: nowrap; }

/* ----- Liste ----- */
section { margin-bottom: 18px; }
section h2 { font-size: 14px; font-weight: 600; color: var(--muted); margin: 0 0 6px 4px; display: flex; align-items: center; gap: 6px; }
section h2 span { background: var(--line); border-radius: 99px; padding: 0 7px; font-size: 12px; }
section h2 .link { margin-left: auto; border: 0; background: none; color: var(--accent); font-weight: 600; font-size: 14px; }
.item {
  display: flex; align-items: center; gap: 4px; background: var(--card); border-radius: 12px;
  margin-bottom: 6px; box-shadow: var(--shadow); min-height: 54px;
}
.check {
  flex: none; width: 26px; height: 26px; margin: 0 4px 0 14px; border-radius: 50%;
  border: 2px solid var(--accent); background: transparent; padding: 0;
}
.txt { flex: 1; padding: 10px 6px; cursor: pointer; min-width: 0; -webkit-user-select: none; user-select: none; }
.nm { font-weight: 500; overflow-wrap: anywhere; }
.q { margin-left: 8px; background: var(--accent-soft); color: var(--accent); border-radius: 6px; padding: 1px 7px; font-size: 14px; font-weight: 600; }
.desc { margin: 4px 0 2px; padding: 6px 8px; background: var(--accent-soft); border-radius: 8px; font-size: 14px; white-space: pre-line; overflow-wrap: anywhere; }
.item.done .desc { background: transparent; padding: 0; }
.txt small { display: block; color: var(--muted); font-size: 13px; }
.edit { flex: none; border: 0; background: none; color: var(--muted); width: 48px; align-self: stretch; font-size: 18px; border-radius: 0 12px 12px 0; }
.item.done { opacity: .55; box-shadow: none; }
.item.done .nm { text-decoration: line-through; }
.item.done .check { background: var(--accent); position: relative; }
.item.done .check::after { content: "✓"; color: #fff; position: absolute; inset: 0; display: grid; place-items: center; font-size: 15px; font-weight: 700; }
.empty { text-align: center; color: var(--muted); margin-top: 60px; font-size: 18px; }

/* ----- Statut / dialogue ----- */
.status {
  position: fixed; left: 50%; bottom: calc(16px + env(safe-area-inset-bottom)); transform: translate(-50%, 250%); opacity: 0;
  background: #333; color: #fff; padding: 8px 16px; border-radius: 99px; font-size: 14px; transition: transform .2s, opacity .2s;
}
.status.show { transform: translate(-50%, 0); opacity: 1; }
dialog { border: 0; border-radius: 16px; padding: 20px; width: min(420px, calc(100vw - 32px)); background: var(--card); color: var(--text); }
dialog::backdrop { background: rgba(0,0,0,.4); }
dialog h2 { margin: 0 0 12px; font-size: 20px; }
dialog label { display: block; font-size: 14px; color: var(--muted); margin-bottom: 10px; }
dialog textarea { resize: vertical; font: inherit; }
dialog input, dialog select, dialog textarea { display: block; width: 100%; margin-top: 4px; padding: 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); color: var(--text); }
.meta { font-size: 13px; color: var(--muted); }
.dlg-actions { display: flex; gap: 8px; margin-top: 16px; }
.dlg-actions span { flex: 1; }
.dlg-actions button { padding: 9px 14px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); }
.dlg-actions .primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.dlg-actions .danger { color: var(--danger); border-color: transparent; background: none; padding-left: 0; }

/* Rayons et magasins : petite liste en colonnes, tout visible d'un coup */
#cats, #mags { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 4px; overflow: visible; }
@media (min-width: 520px) { #cats, #mags { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
#cats .cat, #mags .cat { display: flex; align-items: center; gap: 6px; border-radius: 8px; padding: 6px 8px; text-align: left; white-space: normal; line-height: 1.2; font-size: 13.5px; }
#cats .cat span, #mags .cat span { margin-left: 0; }
#cats .cat.new, #mags .cat.new { justify-content: center; }
.ray-list { display: grid; gap: 6px; margin: 10px 0; }
.ray { display: flex; align-items: center; justify-content: space-between; padding: 8px 10px; background: var(--bg); border-radius: 10px; }
.ray button { border: 0; background: none; color: var(--danger); font-size: 16px; padding: 4px 8px; }
