:root {
  --bg: #f6f1e9;
  --card: #fffdf9;
  --ink: #24211c;
  --muted: #8a8174;
  --line: #e7dfd2;
  --accent: #2f7d5b;
  --accent-soft: #e2efe8;
  --accent-ink: #ffffff;
  --danger: #b4452f;
  --hover: #f1ebe1;
  --radius: 14px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1c1a17;
    --card: #26231f;
    --ink: #f1ece4;
    --muted: #9a9185;
    --line: #36322c;
    --accent: #4caf84;
    --accent-soft: #23362c;
    --accent-ink: #10130f;
    --danger: #e0715a;
    --hover: #2e2a25;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body {
  font: 17px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  min-height: 100dvh;
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
}
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }
.wrap { max-width: 560px; margin: 0 auto; padding: 0 16px 120px; }

/* ---------- En-tête ---------- */
header { display: flex; align-items: center; gap: 10px; padding: 18px 0 10px; }
h1 { font-size: 30px; margin: 0; letter-spacing: -0.02em; flex: 1; }
.status { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 6px; white-space: nowrap; }
/* Petit écran : si le badge « nouveaux » est affiché, le point de statut suffit */
@media (max-width: 430px) {
  header:has(#newBadge:not([hidden])) #statusText { display: none; }
}
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }
.offline .dot { background: var(--danger); }
.badge { white-space: nowrap; font-size: 13px; font-weight: 600; padding: 4px 10px; border-radius: 99px; background: var(--accent); color: var(--accent-ink); }
.icon-btn { width: 40px; height: 40px; border-radius: 12px; font-size: 20px; display: grid; place-items: center; }
.icon-btn[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }

/* ---------- Saisie ---------- */
.add-zone { position: sticky; top: 0; z-index: 2; background: var(--bg); padding: 8px 0 10px; }
form.add { display: flex; gap: 8px; }
input[type=text], select {
  flex: 1; min-width: 0; width: 100%; font: inherit; color: var(--ink);
  background: var(--card); border: 1.5px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; outline: none;
}
input[type=text]:focus, select:focus { border-color: var(--accent); }
.btn-add { width: 54px; flex: none; border-radius: var(--radius); background: var(--accent); color: var(--accent-ink); font-size: 28px; line-height: 1; font-weight: 500; }
.hint { font-size: 12px; color: var(--muted); margin: 6px 4px 0; }
.chips { display: flex; gap: 6px; overflow-x: auto; padding: 8px 0 2px; scrollbar-width: none; align-items: center; }
.chips::-webkit-scrollbar { display: none; }
.chips-title { font-size: 12px; color: var(--muted); flex: none; }
.chips-title:empty { display: none; }
.chip {
  flex: none; display: inline-flex; align-items: center; gap: 6px; padding: 7px 12px 7px 10px;
  border-radius: 99px; background: var(--card); border: 1px solid var(--line); font-size: 15px;
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
}
.chip .ico { color: var(--muted); }
.chip-qty { font-size: 12px; font-weight: 600; color: var(--accent); }
.chip.due { border-color: var(--accent); background: var(--accent-soft); }
.chip.due .ico { color: var(--accent); }
.chip-pack, .chip-basket { border-style: dashed; border-color: var(--accent); }
.chip-pack .ico, .chip-basket .ico { color: var(--accent); }

/* ---------- Icônes ---------- */
.ico { width: 20px; height: 20px; flex: none; display: block; }
.ico-sm { width: 16px; height: 16px; }
.icon-btn .ico { width: 22px; height: 22px; }
.item-icon { color: var(--muted); align-self: center; display: inline-flex; margin-right: 2px; }
.item.done .item-icon { opacity: .5; }
.group-title { display: flex; align-items: center; gap: 6px; }
.group-title .ico { color: var(--muted); }

/* ---------- Progression (mode magasin) ---------- */
.progress { display: none; align-items: center; gap: 10px; margin: 4px 0 6px; font-size: 14px; color: var(--muted); }
.progress-track { flex: 1; height: 6px; border-radius: 99px; background: var(--line); overflow: hidden; }
.progress-bar { height: 100%; background: var(--accent); width: 0; transition: width .3s ease; }

/* ---------- Liste ---------- */
ul { list-style: none; margin: 0; padding: 0; }
.group-title { font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 18px 4px 6px; }
.group:first-child .group-title { margin-top: 8px; }
.item { position: relative; margin-bottom: 8px; border-radius: var(--radius); overflow: hidden; touch-action: pan-y; }
.item:not(.swiping) .swipe-bg { visibility: hidden; }
.swipe-bg { position: absolute; inset: 0; background: var(--danger); color: #fff; font-size: 14px; font-weight: 600; display: flex; align-items: center; justify-content: flex-end; padding-right: 18px; }
.row {
  position: relative; display: flex; align-items: center; gap: 10px;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 4px 4px 4px 12px; min-height: 52px;
}
.check { flex: none; width: 28px; height: 28px; border-radius: 50%; border: 2px solid var(--muted); display: grid; place-items: center; }
.check svg { width: 15px; height: 15px; opacity: 0; color: var(--accent-ink); }
.body { flex: 1; min-width: 0; padding: 10px 0; display: flex; flex-wrap: wrap; align-items: center; gap: 2px 8px; cursor: pointer; user-select: none; -webkit-user-select: none; }
.name { word-break: break-word; }
.qty { font-size: 14px; font-weight: 600; color: var(--accent); background: var(--accent-soft); padding: 1px 7px; border-radius: 8px; }
.note { font-size: 14px; color: var(--muted); width: 100%; padding-left: 30px; }
.who { flex: none; width: 22px; height: 22px; border-radius: 50%; color: #fff; font-size: 12px; font-weight: 700; display: grid; place-items: center; }
.more, .del { flex: none; width: 40px; height: 44px; color: var(--muted); font-size: 22px; border-radius: 10px; }
.item.new .row { border-color: var(--accent); box-shadow: inset 3px 0 0 var(--accent); }
.item.done .row { background: transparent; }
.item.done .name { color: var(--muted); text-decoration: line-through; }
.item.done .check { background: var(--accent); border-color: var(--accent); }
.item.done .check svg { opacity: 1; }

/* Tactile : on supprime en glissant, la croix ne sert que sur les cochés */
@media (hover: none) {
  .todo .del { display: none; }
}
/* Souris (Mac) : croix au survol, retours visuels */
@media (hover: hover) {
  .del { opacity: 0; transition: opacity .15s; }
  .item:hover .del, .del:focus-visible { opacity: 1; }
  .item:hover .row { background: var(--hover); }
  .item.done:hover .row { background: transparent; }
  .more:hover, .del:hover, .icon-btn:hover, .chip:hover { background: var(--hover); }
  .del:hover { color: var(--danger); }
  .btn-add:hover, .btn-main:hover { filter: brightness(1.08); }
}

.section { display: flex; justify-content: space-between; align-items: center; margin: 22px 4px 8px; color: var(--muted); font-size: 14px; }
.clear { color: var(--danger); font-size: 14px; padding: 6px 4px; }
.empty { text-align: center; color: var(--muted); padding: 40px 10px; }
.empty strong { color: var(--ink); display: block; font-size: 20px; margin-bottom: 6px; }

footer { margin-top: 34px; display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 14px; color: var(--muted); }
footer button { padding: 6px 8px; color: var(--muted); }
.share { text-decoration: underline; }
.code { font-family: ui-monospace, Menlo, monospace; font-size: 13px; letter-spacing: .04em; }
.kbd { font-size: 12px; margin-top: 6px; }
@media (hover: none) { .kbd { display: none; } }

/* ---------- Mode magasin ---------- */
body.shop { font-size: 20px; }
body.shop .progress { display: flex; }
body.shop .hint, body.shop .more, body.shop .who { display: none; }
body.shop .item-icon .ico { width: 24px; height: 24px; }
body.shop .row { min-height: 62px; }
body.shop .check { width: 32px; height: 32px; }

/* ---------- Accueil ---------- */
.setup { padding-top: 24px; }
.setup p { color: var(--muted); margin: 18px 0 8px; }
.setup label { display: block; font-size: 14px; color: var(--muted); margin: 18px 0 6px; }
.setup .row-form { display: flex; gap: 8px; }
.setup .row-form button { padding: 0 18px; border-radius: var(--radius); background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.setup .or { text-align: center; margin: 26px 0 10px; font-size: 14px; }
.btn-main, .btn-secondary { width: 100%; padding: 15px; border-radius: var(--radius); font-weight: 600; }
.btn-main { background: var(--accent); color: var(--accent-ink); }
.btn-secondary { border: 1.5px solid var(--line); background: var(--card); }

/* ---------- Fenêtres ---------- */
dialog {
  border: 0; border-radius: 18px; padding: 20px; width: min(92vw, 420px);
  background: var(--card); color: var(--ink); box-shadow: 0 20px 60px rgba(0,0,0,.25);
}
dialog::backdrop { background: rgba(0,0,0,.35); }
dialog h2 { margin: 0 0 14px; font-size: 20px; }
dialog label { display: block; font-size: 13px; color: var(--muted); margin: 12px 0 4px; }
dialog .two { display: grid; grid-template-columns: 1fr 1.6fr; gap: 10px; }
dialog select { padding: 14px 10px; }
dialog .actions { display: flex; gap: 8px; margin-top: 20px; }
dialog .actions button { flex: 1; padding: 13px; border-radius: 12px; font-weight: 600; }
dialog .primary { background: var(--accent); color: var(--accent-ink); }
dialog .ghost { background: var(--hover); }
dialog .danger { color: var(--danger); background: transparent; flex: 0 0 auto !important; }

dialog { max-height: 88dvh; overflow-y: auto; }
dialog h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 22px 0 8px; }
.muted { color: var(--muted); font-size: 14px; margin: 0 0 8px; }
.icon-pick { display: flex; align-items: center; gap: 10px; }
.icon-current { width: 48px; height: 48px; border-radius: 12px; border: 1.5px solid var(--line); display: grid; place-items: center; }
.icon-current .ico { width: 26px; height: 26px; }
.icon-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(44px, 1fr)); gap: 6px; margin-top: 10px; padding: 8px; border-radius: 12px; background: var(--bg); max-height: 220px; overflow-y: auto; }
.icon-choice { height: 44px; border-radius: 10px; display: grid; place-items: center; }
.icon-choice.auto { font-size: 12px; font-weight: 600; color: var(--muted); }
.icon-choice.selected { background: var(--accent); color: var(--accent-ink); }
.check-line { display: flex !important; align-items: center; gap: 8px; font-size: 15px !important; color: var(--ink) !important; margin-top: 16px !important; }
.check-line input { width: 20px; height: 20px; accent-color: var(--accent); }
.trip-list { display: flex; flex-direction: column; gap: 4px; margin: 8px 0; }
.trip-row { display: flex !important; align-items: center; gap: 10px; padding: 10px 8px; border-radius: 10px; font-size: 17px !important; color: var(--ink) !important; margin: 0 !important; }
.trip-row input { width: 22px; height: 22px; accent-color: var(--accent); }
.settings-head { display: flex; align-items: center; justify-content: space-between; }
.settings-head h2 { margin: 0; }
.settings-actions { display: flex; flex-direction: column; gap: 8px; }
.settings-actions button { padding: 12px; border-radius: 12px; font-weight: 600; text-align: left; }
.danger-text { color: var(--danger); }
.pack-list { display: flex; flex-direction: column; gap: 6px; margin-bottom: 8px; }
.pack-row { display: flex; align-items: center; gap: 8px; background: var(--bg); border-radius: 12px; padding: 4px 4px 4px 12px; }
.pack-info { flex: 1; min-width: 0; text-align: left; padding: 8px 0; display: flex; flex-direction: column; }
.pack-items { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pack-del { color: var(--danger); font-size: 14px; padding: 8px; }
.pack-form { display: flex; flex-direction: column; gap: 8px; }
.pack-form button { padding: 12px; border-radius: 12px; font-weight: 600; }
textarea { font: inherit; color: var(--ink); background: var(--card); border: 1.5px solid var(--line); border-radius: var(--radius); padding: 12px 14px; outline: none; resize: vertical; width: 100%; }
textarea:focus { border-color: var(--accent); }
.tips { margin: 0; padding-left: 18px; color: var(--muted); font-size: 14px; display: flex; flex-direction: column; gap: 6px; }
kbd { font: 12px ui-monospace, Menlo, monospace; padding: 1px 5px; border: 1px solid var(--line); border-radius: 5px; }
.done-hint { text-align: center; margin-top: 10px; }

/* ---------- Couleurs des rayons ---------- */
:root { --cat-l: 36%; --cat-bg-l: 93%; }
@media (prefers-color-scheme: dark) { :root { --cat-l: 68%; --cat-bg-l: 20%; } }
.group { --cat: hsl(var(--h, 30) var(--s, 0%) var(--cat-l)); }
.group-title { color: var(--cat); }
.group-title .ico { color: var(--cat); }
.group-title::after { content: ""; flex: 1; height: 2px; border-radius: 2px; margin-left: 6px; background: var(--cat); opacity: .25; }
.group .item:not(.done) .item-icon { color: var(--cat); }
.group .item:not(.done) .row { box-shadow: inset 3px 0 0 hsl(var(--h, 30) var(--s, 0%) var(--cat-l) / .55); }
.group .item.new .row { box-shadow: inset 3px 0 0 var(--accent); }
.chip-item .ico { color: hsl(var(--h, 30) var(--s, 0%) var(--cat-l)); }
.fix-btn { width: 100%; padding: 12px; border-radius: 12px; font-weight: 600; margin-bottom: 6px; }

/* ---------- Filtre pendant la saisie & doublons ---------- */
.filter-info { font-size: 13px; color: var(--muted); padding: 8px 4px 0; }
.filter-info.has-match { color: var(--accent); font-weight: 600; }
body.filtering #done, body.filtering #doneHeader, body.filtering #doneHint { display: none !important; }
body.filtering .item .row { border-color: var(--accent); }
.dupe {
  font-size: 12px; font-weight: 700; color: var(--danger); border: 1px solid currentColor;
  border-radius: 99px; padding: 1px 8px; line-height: 1.5;
}

/* ---------- Tirer pour actualiser ---------- */
html, body { overscroll-behavior-y: contain; }
.pull-indicator {
  position: fixed; left: 50%; top: calc(env(safe-area-inset-top) + 6px); z-index: 20;
  width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center;
  background: var(--card); color: var(--muted); box-shadow: 0 4px 14px rgba(0,0,0,.18);
  transform: translate(-50%, -50px); opacity: 0; pointer-events: none;
}
.pull-indicator svg { width: 20px; height: 20px; }
.pull-indicator.ready { color: var(--accent); }
.pull-indicator.spinning svg { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.status { cursor: pointer; }

/* ---------- Pas trouvé (glisser à droite en magasin) ---------- */
.swipe-bg-right { justify-content: flex-start; padding: 0 0 0 18px; background: #c98a1b; }
.item:not(.swiping-left) .swipe-bg-left, .item:not(.swiping-right) .swipe-bg-right { visibility: hidden; }
.item.missing .row { border-style: dashed; opacity: .75; }
.item.missing .name { color: var(--muted); }
.missing-tag { font-size: 12px; font-weight: 700; color: #b07612; border: 1px solid currentColor; border-radius: 99px; padding: 1px 8px; }
.group-missing { --h: 38; --s: 70%; }
.group-missing .group-title { text-transform: none; letter-spacing: 0; }

/* ---------- Magasins ---------- */
.store-list { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.store-choice { display: inline-flex !important; align-items: center; gap: 6px; padding: 8px 12px; margin: 0 !important;
  border: 1.5px solid var(--line); border-radius: 99px; font-size: 15px !important; color: var(--ink) !important; cursor: pointer; }
.store-choice:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.store-choice input { accent-color: var(--accent); }
.shop-store { font-weight: 600; color: var(--ink); white-space: nowrap; }
.shop-store:empty { display: none; }
#settings .row-form { display: flex; gap: 8px; }
#settings .row-form button { padding: 0 16px; border-radius: 12px; font-weight: 600; }
.backup-row .pack-info strong { font-weight: 600; }

/* ---------- QR code ---------- */
.qr-image { background: #fff; border-radius: 14px; padding: 12px; margin: 4px auto 12px; width: min(72vw, 300px); }
.qr-image svg { display: block; width: 100%; height: auto; }
.qr-dialog, .scan-dialog { text-align: center; }
.scan-frame { position: relative; border-radius: 14px; overflow: hidden; background: #000; aspect-ratio: 1; margin-bottom: 10px; }
.scan-frame video { width: 100%; height: 100%; object-fit: cover; display: block; }
.scan-frame::after { content: ""; position: absolute; inset: 18%; border: 3px solid rgba(255,255,255,.85); border-radius: 16px; }
.setup .btn-main { margin: 4px 0 6px; }

/* ---------- Échec de démarrage ---------- */
.boot-error { max-width: 520px; margin: 40px auto; padding: 18px 20px; border-radius: var(--radius); background: var(--card); border: 1.5px solid var(--danger); display: flex; flex-direction: column; gap: 6px; }
.boot-error strong { color: var(--danger); }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  width: max-content; max-width: calc(100vw - 32px);
  display: flex; align-items: center; gap: 14px;
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 15px;
  opacity: 0; transition: opacity .2s; pointer-events: none; max-width: 92vw; z-index: 10;
}
.toast.show { opacity: 1; pointer-events: auto; }
.toast button { color: var(--accent); font-weight: 700; padding: 4px 2px; filter: brightness(1.4); }
