:root {
  --bg: #fbf8f4;
  --surface: #ffffff;
  --ink: #1d211f;
  --ink-2: #4a524d;
  --muted: #8a918c;
  --line: #ece7df;
  --pine: #1f4d3a;
  --pine-soft: #e8f0eb;
  --berry: #c8373d;
  --berry-soft: #fbeceb;
  --gold: #e7b75f;
  --mine: #fff7e4;
  --radius: 18px;
  --nav-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --shadow: 0 1px 2px rgba(29, 33, 31, .04), 0 4px 16px rgba(29, 33, 31, .06);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; }
body {
  font-family: Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }

.shell {
  max-width: 560px;
  margin: 0 auto;
  min-height: 100dvh;
  padding-bottom: calc(var(--nav-h) + var(--safe-b) + 84px);
  position: relative;
}

/* ---------- Top ---------- */
.top {
  display: flex; align-items: center; gap: 12px;
  padding: calc(18px + env(safe-area-inset-top, 0px)) 16px 10px;
}
.top-text { flex: 1; min-width: 0; }
.top h1 {
  font-family: Fraunces, Georgia, serif; font-weight: 700;
  font-size: 26px; line-height: 1.1; margin: 0; letter-spacing: -.01em;
}
.top h1::after { content: " 🎄"; font-size: .8em; }
.meta { margin: 3px 0 0; color: var(--ink-2); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.me-btn { border: 0; background: none; padding: 0; border-radius: 50%; }

/* ---------- Avatars ---------- */
.av {
  --h: 140;
  display: inline-grid; place-items: center; flex-shrink: 0;
  width: 28px; height: 28px; border-radius: 50%;
  background: hsl(var(--h) 45% 88%); color: hsl(var(--h) 45% 28%);
  font-weight: 700; font-size: 13px;
}
.av.sm { width: 24px; height: 24px; font-size: 11px; }
.av.md { width: 40px; height: 40px; font-size: 16px; }
.av.lg { width: 40px; height: 40px; font-size: 16px; box-shadow: 0 0 0 2px var(--surface), 0 0 0 3.5px hsl(var(--h) 45% 60%); }
.av.empty-av { background: var(--line); color: var(--muted); box-shadow: none; }

/* ---------- Pills catégories ---------- */
.cats {
  position: sticky; top: 0; z-index: 10;
  display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none;
  padding: 10px 16px 12px;
  background: linear-gradient(var(--bg) 80%, rgba(251, 248, 244, 0));
  scroll-snap-type: x proximity;
}
.cats::-webkit-scrollbar { display: none; }
.cats[hidden] { display: none; }
.cat {
  flex-shrink: 0; scroll-snap-align: center;
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--line); background: var(--surface);
  padding: 9px 14px; border-radius: 999px; font-weight: 600; font-size: 14px; color: var(--ink-2);
  transition: background .15s, color .15s, border-color .15s;
}
.cat-emoji { font-size: 16px; }
.cat b {
  font-size: 11px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  display: inline-grid; place-items: center; background: var(--pine-soft); color: var(--pine);
}
.cat.active { background: var(--pine); border-color: var(--pine); color: #fff; }
.cat.active b { background: rgba(255, 255, 255, .2); color: #fff; }

main { padding: 0 16px; }

/* ---------- Blocs & listes ---------- */
.info {
  margin: 4px 0 14px; padding: 12px 14px; border-radius: 14px;
  background: var(--pine-soft); color: var(--pine); font-size: 14px;
}
.block { margin-bottom: 22px; }
.block-head { display: flex; align-items: baseline; gap: 8px; margin: 6px 4px 10px; }
.block-head h2 { margin: 0; font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 700; }
.count { font-size: 12px; font-weight: 700; color: var(--muted); }

.list {
  list-style: none; margin: 0; padding: 0;
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden;
}
.list li + li .row { border-top: 1px solid var(--line); }
.row {
  width: 100%; display: flex; align-items: center; gap: 12px;
  text-align: left; border: 0; background: transparent;
  padding: 14px 14px 14px 16px; min-height: 60px;
  transition: background .12s;
}
.row:active { background: #f6f2ec; }
.row.mine { background: var(--mine); }
.row-emoji { font-size: 22px; }
.row-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.row-title { font-weight: 600; font-size: 16px; }
.row-sub { font-size: 13px; color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-sub i, .who i, .person i { font-style: normal; color: var(--muted); }
.stack { display: flex; }
.stack .av { box-shadow: 0 0 0 2px var(--surface); }
.row.mine .stack .av { box-shadow: 0 0 0 2px var(--mine); }
.stack .av + .av { margin-left: -8px; }
.cta {
  flex-shrink: 0; font-size: 13px; font-weight: 600;
  padding: 7px 12px; border-radius: 999px;
  background: var(--pine-soft); color: var(--pine);
}
.cta.primary { background: var(--berry); color: #fff; }
.row.mine .cta { background: transparent; color: var(--ink-2); padding-right: 4px; }

.empty, .empty-inline, .hint { color: var(--muted); font-size: 14px; }
.empty { text-align: center; padding: 40px 0; }
.empty-inline { margin: 0; padding: 18px 16px; background: var(--surface); border-radius: var(--radius); border: 1.5px dashed var(--line); }
.hint { text-align: center; margin: 10px 0; }
.hint.left { text-align: left; margin: 6px 0 0; }

.empty-state { text-align: center; padding: 48px 20px; }
.empty-state h2 { font-family: Fraunces, Georgia, serif; font-size: 22px; margin: 8px 0 6px; }
.empty-state p { color: var(--ink-2); margin: 0 0 18px; }
.big-emoji { font-size: 52px; }

/* ---------- Invités ---------- */
.stats { display: flex; align-items: center; gap: 10px; margin: 4px 0 14px; }
.stats > div {
  background: var(--surface); box-shadow: var(--shadow); border-radius: 14px;
  padding: 10px 14px; display: flex; flex-direction: column; min-width: 72px;
}
.stats b { font-size: 22px; line-height: 1.1; }
.stats span { font-size: 12px; color: var(--muted); }
.stats .btn { margin-left: auto; }
.notice { margin: 0 0 14px; padding: 12px 14px; border-radius: 14px; background: var(--berry-soft); color: #9b2a2f; font-size: 14px; }
.people { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.person {
  display: flex; gap: 12px; align-items: flex-start;
  background: var(--surface); box-shadow: var(--shadow); border-radius: var(--radius); padding: 14px;
}
.person.mine { background: var(--mine); }
.person-body { flex: 1; min-width: 0; }
.person-name { font-weight: 700; font-size: 16px; margin: 2px 0 4px; }
.person-name small { font-weight: 500; color: var(--muted); }
.person ul { list-style: none; margin: 0; padding: 0; font-size: 14px; color: var(--ink-2); }
.person li { padding: 2px 0; }

/* ---------- Boutons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 0; border-radius: 14px; padding: 13px 18px; font-weight: 600; font-size: 15px;
}
.btn svg { width: 18px; height: 18px; }
.btn.small { padding: 9px 12px; font-size: 14px; border-radius: 12px; }
.btn.full { width: 100%; }
.btn.primary { background: var(--berry); color: #fff; }
.btn.primary:active { filter: brightness(.92); }
.btn.soft { background: var(--pine-soft); color: var(--pine); }
.btn.ghost { background: transparent; border: 1px solid var(--line); }
.danger { color: var(--berry) !important; }
.link { background: none; border: 0; padding: 4px 0; font-weight: 600; font-size: 14px; color: var(--pine); }
.link.center { display: block; margin: 14px auto 0; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 12px; border: 0; flex-shrink: 0;
  background: var(--pine-soft); color: var(--pine); font-weight: 700;
}
.icon-btn.danger { background: var(--berry-soft); }
.icon-btn:disabled { opacity: .35; cursor: default; }

/* ---------- FAB & bottom nav ---------- */
.fab {
  position: fixed; z-index: 20;
  bottom: calc(var(--nav-h) + var(--safe-b) + 16px);
  left: 50%; transform: translateX(-50%);
  display: inline-flex; align-items: center; gap: 8px;
  border: 0; border-radius: 999px; padding: 13px 22px 13px 18px;
  background: var(--ink); color: #fff; font-weight: 600; font-size: 15px;
  box-shadow: 0 8px 24px rgba(29, 33, 31, .25);
}
.fab svg { width: 20px; height: 20px; stroke-width: 2.4; }
.fab[hidden] { display: none; }

.bottom {
  position: fixed; z-index: 30; bottom: 0; left: 0; right: 0;
  display: flex; justify-content: center;
  height: calc(var(--nav-h) + var(--safe-b)); padding-bottom: var(--safe-b);
  background: rgba(255, 255, 255, .94); backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
}
.bottom button {
  position: relative; flex: 1; max-width: 140px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  border: 0; background: none; color: var(--muted); font-size: 11px; font-weight: 600;
}
.bottom button[hidden] { display: none; }
.bottom button.active { color: var(--pine); }
.bottom button.active svg { stroke-width: 2.2; }
.dot-count {
  position: absolute; top: 8px; left: calc(50% + 6px);
  min-width: 17px; height: 17px; padding: 0 4px; border-radius: 9px;
  background: var(--berry); color: #fff; font-size: 10px; display: grid; place-items: center;
}
.dot-count[hidden] { display: none; }

/* ---------- Sheet ---------- */
.sheet {
  border: 0; padding: 8px 20px calc(24px + var(--safe-b));
  width: 100%; max-width: 560px; max-height: 90dvh;
  margin: auto auto 0; border-radius: 24px 24px 0 0;
  background: var(--surface); color: var(--ink);
  box-shadow: 0 -10px 40px rgba(0, 0, 0, .15);
}
.sheet[open] { animation: up .22s cubic-bezier(.2, .8, .2, 1); }
.sheet::backdrop { background: rgba(20, 24, 22, .45); }
@keyframes up { from { transform: translateY(40px); opacity: .4; } }
.sheet-grip { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 4px auto 14px; }
.sheet-kicker { margin: 0 0 2px; font-size: 13px; font-weight: 600; color: var(--muted); }
.sheet-title { font-family: Fraunces, Georgia, serif; font-size: 24px; margin: 0 0 6px; line-height: 1.15; }
.sheet-sub { color: var(--ink-2); margin: 0 0 16px; font-size: 15px; }
.sheet form { display: flex; flex-direction: column; gap: 12px; margin-bottom: 10px; }
.who { list-style: none; margin: 8px 0 18px; padding: 0; }
.who li { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 15px; }
.who li span:not(.av) { flex: 1; }
.who small { color: var(--muted); }

/* ---------- Formulaires ---------- */
input, textarea, select {
  width: 100%; min-width: 0;
  border: 1px solid var(--line); border-radius: 12px; background: #fff;
  padding: 12px 14px; font-size: 16px; /* 16px = pas de zoom iOS */
}
select { appearance: none; background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238a918c' stroke-width='2'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") no-repeat right 12px center / 18px; padding-right: 40px; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--pine); outline-offset: -1px; border-color: transparent; }
.lbl, .form label { display: flex; flex-direction: column; gap: 6px; font-size: 14px; font-weight: 600; color: var(--ink-2); }
.lbl em { font-style: normal; font-weight: 400; color: var(--muted); }

.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.form { display: flex; flex-direction: column; gap: 12px; }
.form textarea { resize: vertical; }
.admin-cat { padding: 12px 0; border-bottom: 1px solid var(--line); display: grid; gap: 8px; }
.admin-cat:first-child { padding-top: 0; }
.admin-row { display: flex; gap: 8px; align-items: center; }
.admin-row input { padding: 10px 12px; }
.emoji-in { width: 52px !important; flex: 0 0 52px; text-align: center; padding: 10px 4px !important; }
.sort-in { width: 56px !important; flex: 0 0 56px; text-align: center; padding: 10px 4px !important; }
.new-cat { padding-top: 14px; }
.mono { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 14px; word-break: break-all; margin: 0; }
code { background: var(--bg); padding: 1px 5px; border-radius: 5px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; z-index: 100; left: 50%; top: calc(14px + env(safe-area-inset-top, 0px));
  transform: translate(-50%, -20px); opacity: 0; pointer-events: none;
  background: var(--ink); color: #fff; padding: 11px 16px; border-radius: 14px;
  font-size: 14px; font-weight: 500; box-shadow: 0 8px 24px rgba(0, 0, 0, .2);
  transition: all .22s; max-width: calc(100vw - 32px); text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: var(--berry); }

/* ---------- Grand écran : rendu « téléphone » centré ---------- */
@media (min-width: 600px) {
  body { background: #efe9e0; }
  .shell { background: var(--bg); box-shadow: 0 0 0 1px var(--line); }
  .cats { background: linear-gradient(var(--bg) 80%, rgba(251, 248, 244, 0)); }
  .bottom { left: 50%; right: auto; width: 560px; transform: translateX(-50%); }
}
@media (prefers-reduced-motion: reduce) { .sheet[open] { animation: none; } }
