:root {
  --bg: #f3f5f2; --card: #fff; --ink: #1b1f1c; --mute: #6b736d; --line: #e3e7e3;
  --acc: #0f7b4a; --acc-soft: #e2f3ea; --danger: #c62828; --radius: 14px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #111412; --card: #1b201d; --ink: #e9eee9; --mute: #9aa39d; --line: #2a312c; --acc: #3ccf86; --acc-soft: #1d3a2b; --danger: #ff6b6b; }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 17px/1.35 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(84px + env(safe-area-inset-bottom)); overscroll-behavior-y: contain; }
body[data-mode="shop"] { padding-bottom: calc(96px + env(safe-area-inset-bottom)); }
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; }
input { font: inherit; color: inherit; }
small { color: var(--mute); font-weight: 400; font-size: 13px; }

/* ---------- en-tête ---------- */
.top { position: sticky; top: 0; z-index: 10; background: var(--acc); color: #fff; padding: env(safe-area-inset-top) 0 0;
  box-shadow: 0 2px 10px #0003; }
@media (prefers-color-scheme: dark) { .top { background: #143d2a; } }
.top-row { display: flex; align-items: center; gap: 8px; padding: 8px 8px 8px 14px; }
.top h1 { font-size: 20px; margin: 0; flex: 1; display: flex; align-items: center; gap: 8px; }
.live { width: 9px; height: 9px; border-radius: 50%; background: #ffb4a8; box-shadow: 0 0 0 2px #fff4; transition: background .3s; }
.live.on { background: #9ff5c6; }
.seg { display: flex; background: #0003; border-radius: 999px; padding: 3px; }
.seg button { padding: 8px 14px; border-radius: 999px; font-size: 15px; font-weight: 600; color: #fffc; white-space: nowrap; }
.seg button.on { background: #fff; color: var(--acc); }
@media (prefers-color-scheme: dark) { .seg button.on { color: #143d2a; } }
.icon-btn { width: 44px; height: 44px; border-radius: 50%; font-size: 22px; display: grid; place-items: center; flex: none; }
.icon-btn:active { background: #0002; }

.search { display: flex; align-items: center; margin: 0 10px 10px; background: var(--card); border-radius: 12px; padding-right: 2px; }
.search input { flex: 1; min-width: 0; border: 0; outline: 0; background: none; padding: 13px 14px; font-size: 18px; color: var(--ink); }
.search input::-webkit-search-cancel-button { display: none; }
.search .icon-btn { color: var(--mute); font-size: 18px; }

.store-tabs { display: flex; gap: 6px; padding: 0 10px 8px; overflow-x: auto; scrollbar-width: none; }
.store-tabs button { position: relative; flex: 1 1 0; min-width: 54px; max-width: 120px; display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 7px 2px 6px; border-radius: 14px; background: #0002; color: #fff; font-weight: 600; font-size: 12px; white-space: nowrap; }
.store-tabs button b { position: absolute; top: 3px; right: 5px; min-width: 20px; padding: 1px 5px; border-radius: 999px; background: #000a;
  color: #fff; font-size: 12px; line-height: 16px; }
.store-tabs button.on { background: #fff; color: var(--c); box-shadow: inset 0 -3px 0 var(--c); }
.store-tabs button.on b { background: var(--c); }
.store-tabs button:not(.on) .logo { opacity: .85; }

/* logos magasins : tuile carrée arrondie, taille --s */
.logo { width: var(--s); height: var(--s); flex: none; display: inline-grid; place-items: center; overflow: hidden; vertical-align: middle;
  border-radius: calc(var(--s) * .24); background: #fff; box-shadow: 0 0 0 1px #0000001a; }
.logo img { width: 84%; height: 84%; object-fit: contain; }
.logo.tile img { width: 100%; height: 100%; }
.logo.all { background: #ffffff38; font-size: calc(var(--s) * .62); box-shadow: none; }
.store-tabs .on .logo.all { background: var(--acc-soft); }
.progress { position: relative; height: 22px; margin: 0 10px 10px; background: #0003; border-radius: 999px; overflow: hidden; }
.progress div { height: 100%; width: 0; background: #9ff5c6; transition: width .3s; }
.progress span { position: absolute; inset: 0; display: grid; place-items: center; font-size: 13px; font-weight: 600; text-shadow: 0 1px 2px #0006; }

/* ---------- listes ---------- */
main { padding: 6px 10px; max-width: 720px; margin: 0 auto; }
.store-h { margin: 18px 4px 8px; font-size: 15px; text-transform: uppercase; letter-spacing: .06em; color: var(--c);
  display: flex; align-items: center; gap: 8px; }
.store-h img.wide { height: 30px; max-width: 170px; object-fit: contain; background: #fff; padding: 4px 8px; border-radius: 8px; box-shadow: 0 0 0 1px #0000001a; }
.sub-h { margin: 26px 4px 10px; font-size: 15px; text-transform: uppercase; letter-spacing: .06em; color: var(--mute); }
.cat-h { margin: 16px 4px 6px; font-size: 14px; font-weight: 600; color: var(--mute); }
.cat-h small { margin-left: 6px; }
.done-h { color: var(--acc); }
.items, .results, .log { list-style: none; margin: 0; padding: 0; background: var(--card); border-radius: var(--radius); overflow: hidden;
  box-shadow: 0 1px 2px #0000000d; }
.item, .res { display: flex; align-items: center; gap: 12px; min-height: 58px; padding: 8px 6px 8px 14px; border-bottom: 1px solid var(--line);
  user-select: none; cursor: pointer; }
.item:last-child, .res:last-child { border-bottom: 0; }
.item:active, .res:active { background: var(--acc-soft); }
.ic { font-size: 22px; width: 28px; text-align: center; flex: none; }
.txt { flex: 1; min-width: 0; display: flex; flex-wrap: wrap; align-items: baseline; column-gap: 8px; }
.nm { font-weight: 500; overflow-wrap: anywhere; }
.qty { display: inline-block; padding: 1px 8px; border-radius: 999px; background: var(--acc-soft); color: var(--acc); font-weight: 700; font-size: 15px; }
.note { flex-basis: 100%; font-size: 13px; color: var(--mute); }
.tag { display: inline-block; padding: 0 7px; border-radius: 6px; font-size: 12px; font-weight: 600; color: #fff; background: var(--c); }
.more, .add-btn { width: 44px; height: 44px; border-radius: 50%; font-size: 22px; color: var(--mute); flex: none; }
.more:active, .add-btn:active { background: var(--line); }
.add-btn { color: var(--acc); font-weight: 700; font-size: 20px; background: var(--acc-soft); }
.res.create .nm { color: var(--acc); font-weight: 700; }
.res.onlist .nm::after { content: " ✓"; color: var(--acc); }

/* mode course : grosse case à cocher */
.shop .item { min-height: 64px; font-size: 19px; }
.box { width: 30px; height: 30px; border-radius: 50%; border: 2.5px solid var(--mute); flex: none; display: grid; place-items: center;
  font-size: 18px; font-weight: 800; color: #fff; transition: all .15s; }
.item.checked .box { background: var(--acc); border-color: var(--acc); }
.item.checked .nm { text-decoration: line-through; color: var(--mute); }
.item.checked .qty { opacity: .5; }
.item.later { opacity: .55; }
.item.later .box { border-style: dashed; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { padding: 9px 13px; border-radius: 999px; background: var(--card); border: 1px solid var(--line); font-size: 15px; }
.chip:active { background: var(--acc-soft); border-color: var(--acc); }
.link { display: block; margin: 14px auto; color: var(--acc); font-weight: 600; padding: 10px; }
.empty { text-align: center; color: var(--mute); padding: 40px 20px; font-size: 17px; }
.empty.ok { color: var(--acc); font-weight: 600; }

/* ---------- pied mode course ---------- */
.foot { position: fixed; left: 0; right: 0; bottom: 0; z-index: 9; padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  background: linear-gradient(transparent, var(--bg) 30%); }
.btn { padding: 12px 18px; border-radius: 12px; background: var(--line); font-weight: 600; }
.btn.primary { background: var(--acc); color: #fff; }
@media (prefers-color-scheme: dark) { .btn.primary { color: #0b1f15; } }
.btn.big { padding: 15px 20px; font-size: 18px; }
.btn.wide { width: 100%; max-width: 720px; display: block; margin: 0 auto; box-shadow: 0 4px 14px #0003; }
.btn:disabled { opacity: .45; box-shadow: none; }
.btn.danger-txt { background: none; color: var(--danger); }

/* ---------- feuille du bas ---------- */
.sheet-back { position: fixed; inset: 0; z-index: 20; background: #0006; }
.sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 21; max-height: 88vh; overflow-y: auto; background: var(--card);
  border-radius: 20px 20px 0 0; padding: 6px 16px calc(18px + env(safe-area-inset-bottom)); transform: translateY(100%);
  transition: transform .22s ease-out; max-width: 720px; margin: 0 auto; overscroll-behavior: contain; }
.sheet.open { transform: none; }
.grab { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 4px auto 10px; }
.sheet h2 { margin: 4px 0 14px; font-size: 21px; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.actions { display: flex; flex-direction: column; }
.act { display: flex; align-items: center; gap: 14px; text-align: left; padding: 14px 6px; font-size: 18px; border-bottom: 1px solid var(--line); min-height: 58px; }
.act:last-child { border-bottom: 0; }
.act span { display: flex; flex-direction: column; }
.act:active { background: var(--acc-soft); }
.act.danger { color: var(--danger); }
.fld { display: block; margin: 0 0 16px; font-size: 14px; font-weight: 600; color: var(--mute); }
.fld > input { display: block; width: 100%; margin-top: 6px; padding: 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); font-size: 17px; font-weight: 400; }
.stepper { display: flex; align-items: center; gap: 8px; margin: 6px 0 8px; }
.stepper button { width: 52px; height: 48px; border-radius: 10px; background: var(--acc-soft); color: var(--acc); font-size: 26px; font-weight: 700; }
.stepper input { width: 90px; height: 48px; text-align: center; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); font-size: 20px; font-weight: 700; }
.pills { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.pill { padding: 8px 12px; border-radius: 999px; border: 1px solid var(--line); font-size: 15px; font-weight: 500; color: var(--ink); background: var(--bg); }
.pill.on { background: var(--acc); border-color: var(--acc); color: #fff; }
.pill.store.on { background: var(--c); border-color: var(--c); }
.sheet-btns { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
.sum { font-size: 17px; line-height: 1.6; }
.log li { padding: 10px 14px; border-bottom: 1px solid var(--line); font-size: 15px; }
.log time { color: var(--mute); font-size: 13px; margin-right: 6px; }

.toast { position: fixed; left: 12px; right: 12px; bottom: calc(16px + env(safe-area-inset-bottom)); z-index: 30; max-width: 600px; margin: 0 auto;
  background: #222; color: #fff; border-radius: 12px; padding: 12px 8px 12px 16px; display: flex; align-items: center; gap: 10px;
  box-shadow: 0 6px 20px #0005; font-size: 16px; }
body[data-mode="shop"] .toast { bottom: calc(86px + env(safe-area-inset-bottom)); }
.toast span { flex: 1; }
.toast .undo { color: #9ff5c6; font-weight: 700; padding: 8px 12px; text-transform: uppercase; font-size: 14px; }

/* ---------- connexion ---------- */
.login-page { display: grid; place-items: center; min-height: 100vh; padding: 20px; }
.login-card { width: 100%; max-width: 380px; background: var(--card); border-radius: 20px; padding: 28px 22px; box-shadow: 0 4px 24px #0001; }
.login-logo { font-size: 48px; text-align: center; }
.login-card h1 { text-align: center; margin: 4px 0 22px; font-size: 24px; }
.login-card label { display: block; font-size: 14px; font-weight: 600; color: var(--mute); margin-bottom: 14px; }
.login-card input { display: block; width: 100%; margin-top: 6px; padding: 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--bg); font-size: 18px; }
.login-card .btn { width: 100%; margin-top: 6px; }
.err { color: var(--danger); text-align: center; min-height: 1.4em; margin: 12px 0 0; }

.pill.store { display: inline-flex; align-items: center; gap: 7px; padding: 5px 12px 5px 5px; }
.note .logo { margin-right: 2px; }
.item > .logo { margin-right: 2px; }
.act .logo { margin: -4px 0; }
