:root {
  --bg: #f6efe9;
  --surface: #ffffff;
  --surface-2: #fbf6f2;
  --text: #2b1f22;
  --muted: #8a7a7d;
  --line: #ecdfd7;
  --accent: #e8577a;
  --accent-2: #ff9a76;
  --accent-soft: #fde4ea;
  --ok: #3fae7a;
  --ok-soft: #dcf3e8;
  --danger: #d9434b;
  --urgent: #ff7a2f;
  --shadow: 0 6px 24px rgba(80, 40, 40, .10);
  --radius: 16px;
  --top-h: 0px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1b1517; --surface: #261e21; --surface-2: #2f2629; --text: #f5ecee; --muted: #a8979b; --line: #3a2f33;
    --accent: #ff6f91; --accent-2: #ffa07f; --accent-soft: #452631; --ok: #4fc58e; --ok-soft: #1f3a2d; --danger: #ff6b6b;
    --shadow: 0 6px 24px rgba(0, 0, 0, .35); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #1b1517; --surface: #261e21; --surface-2: #2f2629; --text: #f5ecee; --muted: #a8979b; --line: #3a2f33;
  --accent: #ff6f91; --accent-2: #ffa07f; --accent-soft: #452631; --ok: #4fc58e; --ok-soft: #1f3a2d; --danger: #ff6b6b;
  --shadow: 0 6px 24px rgba(0, 0, 0, .35); color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Rounded", "Segoe UI", Roboto, system-ui, sans-serif;
  -webkit-font-smoothing: antialiased; overscroll-behavior-y: none;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }

/* ---------- Boutons ---------- */
.btn { padding: 10px 16px; border-radius: 12px; background: var(--surface-2); border: 1px solid var(--line); font-weight: 600; }
.btn.primary { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; border: 0; }
.btn.danger { color: var(--danger); }
.btn.big { width: 100%; padding: 14px; font-size: 17px; border-radius: 14px; }
.btn.small { padding: 6px 12px; font-size: 14px; }
.icon-btn { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; font-size: 20px; flex: none; }
.icon-btn:active { background: var(--surface-2); }

/* ---------- Login ---------- */
.login { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.login-card { width: 100%; max-width: 380px; background: var(--surface); border-radius: 24px; padding: 28px 22px; box-shadow: var(--shadow); text-align: center; }
.login-logo { font-size: 54px; position: relative; display: inline-block; }
.login-logo span { position: absolute; font-size: 24px; right: -10px; top: -4px; }
.login h1 { margin: 6px 0 2px; }
.login form { text-align: left; margin-top: 18px; display: grid; gap: 12px; }
label { font-size: 14px; font-weight: 600; color: var(--muted); display: grid; gap: 6px; }
input:not([type=checkbox]), select, textarea {
  width: 100%; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface-2); color: var(--text); font-size: 16px; font-weight: 400;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.error { color: var(--danger); min-height: 1em; margin: 0; font-size: 14px; }
.colors { display: flex; gap: 10px; flex-wrap: wrap; }
.color { width: 34px; height: 34px; border-radius: 50%; border: 3px solid transparent; }
.color.sel { border-color: var(--text); }

/* ---------- Header ---------- */
.top {
  position: sticky; top: 0; z-index: 10; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  padding: calc(env(safe-area-inset-top) + 8px) 12px 0;
}
.top-row { display: flex; align-items: center; gap: 4px; }
.title-wrap { flex: 1; min-width: 0; padding-left: 4px; }
.top h1 { margin: 0; font-size: 24px; letter-spacing: -.02em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.status { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.status .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.status.online .dot { background: var(--ok); box-shadow: 0 0 0 3px var(--ok-soft); }
.status.offline .dot { background: var(--urgent); }
.presence { display: flex; margin-right: 4px; }
.avatar {
  width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-size: 13px; font-weight: 700;
  border: 2px solid var(--bg); margin-left: -6px; flex: none;
}
.avatar.live { animation: pop .3s ease; }
.tabs { display: flex; gap: 8px; overflow-x: auto; padding: 10px 2px 10px; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: none; padding: 8px 14px; border-radius: 999px; background: var(--surface); border: 1px solid var(--line); font-weight: 600; font-size: 15px;
  display: flex; gap: 6px; align-items: center; white-space: nowrap;
}
.tab .n { font-size: 12px; background: var(--surface-2); padding: 1px 7px; border-radius: 999px; color: var(--muted); }
.tab.active { background: var(--text); color: var(--bg); border-color: var(--text); }
.tab.active .n { background: color-mix(in srgb, var(--bg) 20%, transparent); color: var(--bg); }
.tab.add { color: var(--muted); }
.progress { height: 3px; background: transparent; margin: 0 -12px; }
.progress div { height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), var(--accent-2)); transition: width .4s ease; }

/* ---------- Liste ---------- */
main { padding: 4px 12px calc(150px + env(safe-area-inset-bottom)); max-width: 680px; margin: 0 auto; }
.group { margin-top: 14px; }
.group-h { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 0 6px 6px; display: flex; gap: 6px; align-items: center; }
.group-h .c { margin-left: auto; font-weight: 600; }
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.item-wrap { position: relative; overflow: hidden; }
.item-wrap + .item-wrap { border-top: 1px solid var(--line); }
.item-wrap .swipe-bg { position: absolute; inset: 0; background: var(--danger); color: #fff; display: flex; align-items: center; justify-content: flex-end; padding-right: 22px; font-weight: 700; }
.item {
  position: relative; display: flex; align-items: center; gap: 12px; padding: 12px 10px 12px 14px; min-height: 56px; background: var(--surface);
  user-select: none; -webkit-user-select: none; touch-action: pan-y; transition: transform .2s ease;
}
.item.dragging { transition: none; }
.check {
  width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--line); flex: none; display: grid; place-items: center; color: #fff; font-size: 15px; font-weight: 800;
  transition: all .15s ease;
}
.item.done .check { background: var(--ok); border-color: var(--ok); }
.item.urgent .check { border-color: var(--urgent); }
.item .body { flex: 1; min-width: 0; }
.item .name { font-weight: 600; overflow-wrap: anywhere; }
.item.done .name { text-decoration: line-through; color: var(--muted); font-weight: 500; }
.qty { display: inline-block; font-size: 13px; font-weight: 700; color: var(--accent); background: var(--accent-soft); padding: 1px 8px; border-radius: 999px; margin-left: 4px; vertical-align: 1px; }
.item.done .qty { color: var(--muted); background: var(--surface-2); }
.meta { font-size: 13px; color: var(--muted); margin-top: 2px; overflow-wrap: anywhere; }
.flame { margin-left: 4px; }
.who { width: 22px; height: 22px; font-size: 11px; border: 0; margin: 0; }
.more { width: 34px; height: 34px; border-radius: 10px; color: var(--muted); font-size: 18px; flex: none; }
.item.flash { animation: flash 1.2s ease; }

.cart-h { display: flex; align-items: center; gap: 8px; margin: 22px 6px 8px; }
.cart-h button.toggle { font-weight: 700; color: var(--muted); font-size: 14px; display: flex; gap: 6px; align-items: center; padding: 6px 0; }
.cart-h .spacer { flex: 1; }
.totals { font-size: 13px; color: var(--muted); margin: 8px 6px; text-align: right; }

.empty { text-align: center; padding: 56px 20px 20px; color: var(--muted); }
.empty .big { font-size: 56px; }
.empty h2 { color: var(--text); margin: 8px 0 4px; font-size: 20px; }

/* ---------- Barre d'ajout ---------- */
.addbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  padding: 8px 12px calc(10px + env(safe-area-inset-bottom));
  background: linear-gradient(to top, var(--bg) 70%, color-mix(in srgb, var(--bg) 0%, transparent));
}
.add-row { display: flex; gap: 8px; align-items: center; max-width: 680px; margin: 0 auto; background: var(--surface); border-radius: 18px; padding: 6px; box-shadow: var(--shadow); }
.add-row input { border: 0; background: transparent; padding: 10px 8px; }
.add-row input:focus { outline: none; }
.add-btn { width: 44px; height: 44px; border-radius: 14px; flex: none; background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; font-size: 24px; font-weight: 700; }
#micBtn.rec { background: var(--accent-soft); animation: pulse 1s infinite; }
.suggest { display: flex; gap: 8px; overflow-x: auto; padding: 0 2px 8px; max-width: 680px; margin: 0 auto; scrollbar-width: none; }
.suggest::-webkit-scrollbar { display: none; }
.chip { flex: none; padding: 7px 12px; border-radius: 999px; background: var(--surface); border: 1px solid var(--line); font-size: 14px; font-weight: 600; white-space: nowrap; box-shadow: 0 2px 8px rgba(0,0,0,.04); }
.chip.hint { color: var(--muted); font-weight: 500; }
.chip .x { margin-left: 6px; color: var(--muted); }

/* ---------- Mode magasin ---------- */
body.shop .item { min-height: 66px; padding-top: 16px; padding-bottom: 16px; }
body.shop .item .name { font-size: 19px; }
body.shop .check { width: 32px; height: 32px; }
body.shop .more, body.shop .who { display: none; }
body.shop #shopBtn { background: var(--accent-soft); }
body.shop .addbar .suggest { display: none; }

/* ---------- Sheet ---------- */
.sheet-wrap { position: fixed; inset: 0; z-index: 50; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(20, 10, 12, .45); animation: fade .2s ease; }
.sheet {
  position: absolute; left: 0; right: 0; bottom: 0; max-height: 88vh; overflow-y: auto; background: var(--surface);
  border-radius: 24px 24px 0 0; padding: 10px 18px calc(22px + env(safe-area-inset-bottom)); animation: up .25s cubic-bezier(.2,.9,.3,1);
  max-width: 680px; margin: 0 auto;
}
.sheet::before { content: ""; display: block; width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 12px; }
.sheet h2 { margin: 4px 0 14px; font-size: 20px; }
.sheet h3 { margin: 18px 0 8px; font-size: 14px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.form { display: grid; gap: 12px; }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; }
.actions { display: flex; gap: 10px; margin-top: 16px; }
.actions .btn { flex: 1; }
.switch { display: flex; align-items: center; justify-content: space-between; padding: 10px 0; color: var(--text); font-size: 16px; font-weight: 500; }
.switch input { width: 46px; height: 28px; appearance: none; -webkit-appearance: none; background: var(--line); border-radius: 999px; position: relative; transition: .2s; flex: none; }
.switch input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; transition: .2s; box-shadow: 0 1px 3px rgba(0,0,0,.2); }
.switch input:checked { background: var(--ok); }
.switch input:checked::after { left: 21px; }
.menu-list { display: grid; gap: 2px; }
.menu-item { display: flex; align-items: center; gap: 14px; padding: 14px 6px; border-radius: 12px; text-align: left; font-weight: 600; width: 100%; }
.menu-item:active { background: var(--surface-2); }
.menu-item .e { font-size: 22px; width: 28px; text-align: center; }
.menu-item small { display: block; color: var(--muted); font-weight: 400; }
.cat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 6px; }
.cat-opt { padding: 9px 10px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface-2); text-align: left; font-size: 14px; font-weight: 600; }
.cat-opt.sel { border-color: var(--accent); background: var(--accent-soft); }
.feed { display: grid; gap: 2px; }
.feed-item { display: flex; gap: 10px; align-items: flex-start; padding: 8px 2px; }
.feed-item .t { font-size: 12px; color: var(--muted); }
.recipe { display: flex; align-items: center; gap: 10px; padding: 12px; border: 1px solid var(--line); border-radius: 14px; margin-bottom: 8px; }
.recipe .body { flex: 1; min-width: 0; }
.recipe .meta { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.emoji-row { display: flex; gap: 6px; flex-wrap: wrap; }
.emoji-opt { font-size: 22px; width: 42px; height: 42px; border-radius: 12px; background: var(--surface-2); border: 1px solid var(--line); }
.emoji-opt.sel { border-color: var(--accent); background: var(--accent-soft); }
.stepper { display: flex; align-items: center; gap: 6px; }
.stepper button { width: 44px; height: 44px; border-radius: 12px; background: var(--surface-2); border: 1px solid var(--line); font-size: 20px; flex: none; }

/* ---------- Toasts ---------- */
.toasts { position: fixed; left: 0; right: 0; bottom: calc(120px + env(safe-area-inset-bottom)); z-index: 60; display: grid; gap: 8px; justify-items: center; pointer-events: none; padding: 0 16px; }
.toast {
  pointer-events: auto; background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 14px; font-size: 15px; display: flex; gap: 12px; align-items: center;
  box-shadow: var(--shadow); animation: up .25s ease; max-width: 520px;
}
.toast button { color: var(--accent-2); font-weight: 700; }
.toast.out { opacity: 0; transform: translateY(10px); transition: .25s; }

.confetti { position: fixed; top: -20px; z-index: 70; pointer-events: none; font-size: 22px; animation: fall linear forwards; }

@keyframes up { from { transform: translateY(30px); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { 0% { transform: scale(.4); } 70% { transform: scale(1.15); } }
@keyframes pulse { 50% { opacity: .5; } }
@keyframes flash { 0%, 40% { background: var(--accent-soft); } }
@keyframes fall { to { transform: translateY(110vh) rotate(540deg); } }
