:root {
  --bg: #faf7f2; --card: #fff; --ink: #2a2522; --muted: #7a706a; --line: #e8e1d8;
  --red: #c0392b; --red-d: #a02f23; --green: #2e7d4f; --green-bg: #e7f4ec; --gold: #d9a441;
  --radius: 12px; --shadow: 0 1px 3px rgba(0,0,0,.06), 0 4px 14px rgba(0,0,0,.04);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #1b1817; --card: #252120; --ink: #f1ebe6; --muted: #a89d95; --line: #3a3431;
    --green-bg: #1f3a2a; --shadow: none; }
}
* { box-sizing: border-box; }
body { margin: 0; font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--ink); }
a { color: inherit; }
h1 { margin: 0; font-size: 1.4rem; }
h2 { font-size: 1.1rem; margin: 1.4rem 0 .6rem; }
main { max-width: 1100px; margin: 0 auto; padding: 16px; }
.top { background: var(--red); color: #fff; padding: 14px 16px 0; }
.top-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; max-width: 1100px; margin: 0 auto; padding-bottom: 12px; flex-wrap: wrap; }
#userBox { display: flex; align-items: center; gap: 8px; }
button.ghost { background: transparent; color: #fff; border-color: rgba(255,255,255,.5); padding: 4px 10px; }
footer { text-align: center; padding: 24px 16px 40px; }
.people { list-style: none; padding: 0; margin: 0 0 10px; display: flex; flex-direction: column; gap: 6px; }
.people li { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.people li input { max-width: 220px; flex: 1; }
.mylists { padding-left: 18px; } .mylists li { margin: 4px 0; }
nav { display: flex; gap: 4px; overflow-x: auto; max-width: 1100px; margin: 0 auto; }
nav button { background: transparent; color: #fff; border: 0; padding: 10px 14px; border-radius: 10px 10px 0 0; cursor: pointer; font: inherit; white-space: nowrap; opacity: .85; }
nav button.active { background: var(--bg); color: var(--ink); opacity: 1; font-weight: 600; }

button { font: inherit; cursor: pointer; border-radius: 8px; border: 1px solid var(--line); padding: 8px 14px; background: var(--card); color: var(--ink); }
button.primary { background: var(--red); border-color: var(--red); color: #fff; font-weight: 600; }
button.primary:hover { background: var(--red-d); }
button.secondary:hover { border-color: var(--muted); }
button.icon { border: 0; background: none; padding: 6px; }
button.link { border: 0; background: none; padding: 0; text-decoration: underline; color: var(--red); }
input, select { font: inherit; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--card); color: var(--ink); width: 100%; min-width: 0; }
label { display: block; margin: 8px 0; font-size: .9rem; color: var(--muted); }
label > input, label > select, label > .row { margin-top: 4px; color: var(--ink); }
label.check { display: flex; gap: 8px; align-items: flex-start; color: var(--ink); }
label.check input { width: auto; margin-top: 3px; }
.row { display: flex; gap: 8px; align-items: flex-end; }
.grow { flex: 1; }
.muted { color: var(--muted); } .small { font-size: .85rem; } .center { text-align: center; }
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); border: 1px solid var(--line); padding: 16px; margin-bottom: 14px; }
.card h2 { margin-top: 0; }
.narrow { max-width: 420px; margin: 40px auto; }
.pending { display: flex; gap: 14px; align-items: flex-start; border: 2px solid var(--gold); }
.pending p { margin-top: 0; }
.hint { background: var(--green-bg); padding: 10px 14px; border-radius: 10px; }

.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.toolbar select { width: auto; }
.thumb { width: 56px; height: 56px; object-fit: contain; background: #fff; border-radius: 8px; border: 1px solid var(--line); flex: none; }
.thumb[src=""], img[src=""] { visibility: hidden; }

/* liste admin */
.glist { display: flex; flex-direction: column; gap: 8px; }
.grow-row { display: grid; grid-template-columns: 56px minmax(0,1fr) 90px 140px 150px auto; gap: 10px; align-items: center;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 10px; }
.grow-row.taken { border-left: 4px solid var(--green); }
.grow-row .title { font-weight: 600; text-decoration: none; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.grow-row .title:hover { text-decoration: underline; }
.actions { display: flex; }
@media (max-width: 760px) {
  .grow-row { grid-template-columns: 56px minmax(0,1fr) auto; }
  .grow-row .price, .grow-row select, .grow-row input[data-f=takenBy] { grid-column: 1 / -1; }
  .grow-row .actions { grid-row: 1; grid-column: 3; }
}

/* stats */
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 12px; }
.stat h3 { margin: 0 0 6px; }
.stat .big { font-size: 1.5rem; font-weight: 700; } .stat .big small { font-size: .9rem; font-weight: 400; color: var(--muted); }
.bar { height: 8px; background: var(--line); border-radius: 4px; margin: 8px 0; overflow: hidden; }
.bar span { display: block; height: 100%; background: var(--gold); }
.tbl { width: 100%; border-collapse: collapse; background: var(--card); border-radius: var(--radius); overflow: hidden; border: 1px solid var(--line); }
.tbl th, .tbl td { text-align: left; padding: 8px 12px; border-bottom: 1px solid var(--line); }

/* vue famille */
.me-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; justify-content: space-between; }
.me-bar form { flex: 1; min-width: 260px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; border-radius: 0; }
.seg button.active { background: var(--ink); color: var(--bg); }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }
.gcard { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; display: flex; flex-direction: column; box-shadow: var(--shadow); }
.gcard .imgbox { display: block; aspect-ratio: 1; background: #fff; }
.gcard .imgbox img { width: 100%; height: 100%; object-fit: contain; padding: 10px; }
.gcard .body { padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 4px; flex: 1; }
.gcard .title { font-weight: 600; text-decoration: none; }
.gcard .price-tag { font-weight: 700; font-size: 1.1rem; margin-top: auto; padding-top: 6px; }
.gcard button { width: 100%; margin-top: 6px; }
.gcard.struck { opacity: .55; }
.gcard.struck .title, .gcard.struck .price-tag { text-decoration: line-through; }
.gcard.struck img { filter: grayscale(1); }
.gcard.mine { border: 2px solid var(--green); }
.badge { background: var(--line); border-radius: 6px; padding: 4px 8px; font-size: .85rem; text-align: center; margin-top: 6px; }

/* réglages */
.kids { list-style: none; padding: 0; margin: 0 0 10px; display: flex; flex-direction: column; gap: 6px; }
.kids li { display: flex; gap: 8px; align-items: center; }
.kids li input { max-width: 260px; }
.bookmarklet { display: inline-block; background: var(--gold); color: #2a2522; padding: 8px 16px; border-radius: 20px; font-weight: 700; text-decoration: none; cursor: grab; }

dialog { border: 0; border-radius: var(--radius); padding: 20px; width: min(520px, calc(100vw - 32px)); background: var(--card); color: var(--ink); }
dialog::backdrop { background: rgba(0,0,0,.4); }
dialog h2 { margin-top: 0; }
dialog menu { display: flex; justify-content: flex-end; gap: 8px; padding: 0; margin: 16px 0 0; }
#toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 20px; z-index: 99; }

/* groupes & destinataires */
.group-title { font-size: 1.25rem; margin: 1.6rem 0 .2rem; padding-bottom: 4px; border-bottom: 2px solid var(--gold); }
.recipient { font-size: 1.05rem; margin: 1rem 0 .5rem; }
.group-h { margin-top: 1.6rem; }
.group-h .muted { font-weight: 400; }
.card .group-title { font-size: 1rem; margin-top: 1rem; }
.group-in { max-width: 160px; }
.row.wrap { flex-wrap: wrap; align-items: center; }
.people li { flex-direction: column; align-items: stretch; padding: 8px 0; border-bottom: 1px solid var(--line); }
.secrets { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 6px; }
.chip { display: inline-flex; align-items: center; gap: 4px; margin: 0; padding: 3px 10px; border: 1px solid var(--line); border-radius: 14px; color: var(--ink); cursor: pointer; font-size: .85rem; }
.chip input { width: auto; margin: 0; }
.chip.on { background: var(--green-bg); border-color: var(--green); }

/* cadeaux personnels & communs */
.grow-row.private { background: repeating-linear-gradient(135deg, var(--card), var(--card) 10px, var(--line) 10px, var(--line) 11px); }
.joint { color: var(--green); margin-top: 2px; }
.joints { list-style: none; padding: 0; margin: 0 0 12px; }
.joints li { padding: 8px 0; border-bottom: 1px solid var(--line); }
.joints .row input[data-kid] { max-width: 220px; }
.chip label { display: inline-flex; align-items: center; gap: 4px; margin: 0; color: inherit; cursor: pointer; }
.chip input.pct { width: 52px; padding: 2px 4px; text-align: right; }
.small-btn { padding: 4px 10px; font-size: .85rem; }
#jointForm { margin-top: 8px; }

/* déjà acheté / remboursements */
.bought { color: var(--gold); margin-top: 2px; }
fieldset.buy { border: 1px solid var(--line); border-radius: 10px; padding: 4px 12px 8px; margin: 10px 0; }
.refunds-h { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin: 6px 0; font-size: .9rem; color: var(--muted); flex-wrap: wrap; }
.refund-row { display: flex; gap: 6px; align-items: center; margin-bottom: 6px; flex-wrap: wrap; }
.refund-row input[data-r=name] { flex: 2; min-width: 120px; }
.refund-row input[data-r=amount] { width: 80px; flex: none; }
.refund-row label.check { margin: 0; width: auto; }
.debt-h h3 { margin: 0; }
.big-amount { font-size: 1.3rem; font-weight: 700; }
.debt.done { opacity: .6; }
.debt-lines { list-style: none; padding: 0; margin: 8px 0 0; }
.debt-lines li { display: flex; justify-content: space-between; align-items: center; gap: 8px; border-top: 1px solid var(--line); padding: 4px 0; }
.debt-lines li label { margin: 0; }
.debt-lines li.paid span { text-decoration: line-through; color: var(--muted); }
.owe { color: var(--red); }
.bought-toggle { margin: 6px 0 0; font-size: .9rem; }

/* cartes cliquables + fiche */
.gcard button.imgbox, .gcard button.title { border: 0; padding: 0; background: none; text-align: left; font: inherit; color: inherit; cursor: pointer; width: 100%; border-radius: 0; }
.gcard button.imgbox { background: #fff; }
.gcard button.title { font-weight: 600; }
.gcard button.title:hover { text-decoration: underline; }
#ficheDlg { width: min(560px, calc(100vw - 24px)); max-height: calc(100vh - 32px); overflow: auto; }
#ficheDlg form { position: relative; }
.fiche-close { position: absolute; right: 4px; top: 4px; z-index: 2; width: 36px; height: 36px; border-radius: 50%; background: var(--card) !important; box-shadow: 0 1px 4px rgba(0,0,0,.25); font-size: 1rem; }
#ficheDlg .price-tag { font-size: 1.4rem; font-weight: 700; }
.fiche-img { display: block; width: 100%; max-height: 50vh; object-fit: contain; background: #fff; border-radius: 10px; margin-bottom: 10px; }
#ficheDlg h2 { margin: 6px 0; padding-right: 24px; }
.fiche-desc { white-space: pre-line; line-height: 1.5; }
a.btn-link { display: inline-block; padding: 8px 14px; border: 1px solid var(--line); border-radius: 8px; text-decoration: none; }

/* mobile : cartes compactes (image + prix), le reste au clic dans la fiche */
@media (max-width: 600px) {
  main { padding: 12px; }
  .top h1 { font-size: 1.15rem; }
  .me-bar { flex-direction: column; align-items: stretch; }
  .seg { display: flex; } .seg button { flex: 1; padding: 8px 4px; }
  .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .gcard .body { padding: 6px 8px 8px; gap: 2px; }
  .gcard .body > .muted.small { display: none; }
  .gcard button.title { font-size: .85rem; font-weight: 500; display: -webkit-box; -webkit-line-clamp: 1; -webkit-box-orient: vertical; overflow: hidden; }
  .gcard .price-tag { font-size: 1.05rem; padding-top: 2px; }
  .gcard button[data-act], .gcard .badge { font-size: .8rem; padding: 6px 4px; }
  .gcard .imgbox img { padding: 4px; }
  .bought-toggle { font-size: .8rem; }
  dialog { padding: 16px; }
}

/* organisateurs */
.owners { list-style: none; padding: 0; margin: 0 0 8px; }
.owners li { display: flex; align-items: center; justify-content: space-between; padding: 4px 0; border-bottom: 1px solid var(--line); }
.invite-card { border: 2px solid var(--gold); }

/* familles & qui voit quoi */
.ghost-link { color: #fff; font-size: .85rem; margin-right: 6px; }
.card-in { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin: 10px 0; }
.fam-h { align-items: center; }
.fam-ico { font-size: 1.2rem; }
.fam-name { font-weight: 700; max-width: 260px; }
.members { list-style: none; padding: 0; margin: 8px 0; }
.members li { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; padding: 5px 0; border-top: 1px solid var(--line); }
.members .m-name { max-width: 160px; }
.members select { width: auto; }
label.check.inline { display: inline-flex; margin: 0; align-items: center; gap: 4px; font-size: .85rem; }
.madd input, .madd select { width: auto; }
.add-fam { cursor: pointer; background: var(--card); }
.matrix-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border: 1px solid var(--line); border-radius: 10px; }
.matrix { border-collapse: collapse; font-size: .85rem; min-width: 100%; }
.matrix th, .matrix td { border: 1px solid var(--line); padding: 4px 6px; text-align: center; white-space: nowrap; }
.matrix .corner { text-align: left; background: var(--card); position: sticky; left: 0; z-index: 2; }
.matrix .vrow { text-align: left; background: var(--card); position: sticky; left: 0; z-index: 1; }
.matrix .vrow .link { display: block; font-size: .75rem; }
.matrix .fam-col { background: var(--green-bg); }
.matrix .rcol { font-weight: 500; }
.matrix td.self { color: var(--muted); background: var(--line); }
.matrix .cell { border: 0; background: none; font-size: 1.1rem; padding: 2px 6px; cursor: pointer; }
.matrix .cell.off { background: #fde7e4; border-radius: 6px; }
@media (prefers-color-scheme: dark) { .matrix .cell.off { background: #4a2420; } }
.img-pick { margin: 4px 0 8px; }
.link-like { display: inline; color: var(--red); text-decoration: underline; cursor: pointer; margin: 0; }
.grow-row.vis-reserve { background: repeating-linear-gradient(135deg, var(--card), var(--card) 10px, #f6ecd6 10px, #f6ecd6 11px); border-left: 4px solid var(--gold); }
@media (prefers-color-scheme: dark) { .grow-row.vis-reserve { background: repeating-linear-gradient(135deg, var(--card), var(--card) 10px, #3a3020 10px, #3a3020 11px); } }
.vis-sel { width: auto; padding: 4px 6px; font-size: .85rem; }
