:root {
  --bg: #f5f3ee;
  --panel: #ffffff;
  --ink: #1d2433;
  --muted: #6b7280;
  --line: #e4e0d6;
  --accent: #1f3a68;
  --accent-soft: #e6ecf7;
  --gold: #b8892b;
  --ok: #1d7a46;
  --ok-soft: #e3f3e9;
  --warn: #a15c07;
  --warn-soft: #fdf0dc;
  --bad: #b42318;
  --bad-soft: #fde8e6;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 2px 8px rgba(0,0,0,.04);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171d; --panel: #1c2029; --ink: #e8e6e1; --muted: #9aa1ad; --line: #2c313c;
    --accent: #8fb0ea; --accent-soft: #243149; --gold: #d9ad55;
    --ok: #5fcf8e; --ok-soft: #1c3326; --warn: #f0b35a; --warn-soft: #3a2c16; --bad: #f28b82; --bad-soft: #3b1f1d;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; } /* sinon display:flex des onglets l'emporte sur l'attribut hidden */
body { margin: 0; background: var(--bg); color: var(--ink); font: 14px/1.45 system-ui, "Segoe UI", sans-serif; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }

.topbar {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 24px;
  padding: 10px 24px; background: var(--panel); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; font-size: 16px; white-space: nowrap; }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.tabs button {
  border: 0; background: none; padding: 7px 14px; border-radius: 999px; cursor: pointer; color: var(--muted); font-weight: 600;
}
.tabs button:hover { background: var(--accent-soft); color: var(--ink); }
.tabs button.active { background: var(--accent); color: var(--panel); }
.save-status { margin-left: auto; font-size: 12px; color: var(--muted); white-space: nowrap; }
.save-status.error { color: var(--bad); font-weight: 600; }

main { max-width: 1180px; margin: 0 auto; padding: 20px 24px 60px; }
.loading { color: var(--muted); }

h2 { font-size: 20px; margin: 0 0 4px; }
h3 { font-size: 15px; margin: 22px 0 8px; }
.sub { color: var(--muted); margin: 0 0 16px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin-bottom: 14px; }
.toolbar .spacer { flex: 1; }

input[type=text], input[type=search], input[type=number], input[type=url], select, textarea {
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.btn {
  border: 1px solid var(--line); background: var(--panel); border-radius: 8px; padding: 7px 12px; cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--panel); font-weight: 600; }
.btn.small { padding: 3px 8px; font-size: 12px; }
.btn.ghost { border-color: transparent; background: none; }
.btn.danger { color: var(--bad); }
.btn:disabled { opacity: .5; cursor: wait; }

.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: var(--panel); padding: 6px 12px; cursor: pointer; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.active { background: var(--accent-soft); font-weight: 600; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; }
.chip {
  border: 1px solid var(--line); background: var(--panel); border-radius: 999px; padding: 5px 12px; cursor: pointer;
}
.chip.active { background: var(--accent); border-color: var(--accent); color: var(--panel); }
.chip .count { opacity: .75; font-size: 12px; margin-left: 4px; }
.chip.todo:not(.active) { border-color: var(--gold); color: var(--gold); font-weight: 600; }

/* onglet Promos : filtres série / événement et saut vers une série (comme dlpromos.ink/browse) */
.promo-filters select { max-width: 100%; min-width: 0; }
.promo-filters .promo-count { margin-left: auto; }
.promo-jump .chip { font-size: 13px; font-weight: 600; letter-spacing: .03em; }
.group-head { scroll-margin-top: 72px; }

/* rareté */
.rar { display: inline-block; min-width: 26px; text-align: center; font-size: 11px; font-weight: 700; border-radius: 5px; padding: 1px 5px; background: var(--accent-soft); }
.rar-C { background: #e9e9e9; color: #444; }
.rar-U { background: #e2e8f0; color: #334155; }
.rar-R { background: #f3e1c8; color: #7a4a0b; }
.rar-S { background: #e0e7f5; color: #2d4a86; }
.rar-L { background: #f7e9a8; color: #6b5200; }
.rar-Ep { background: #f6d9ea; color: #8a1f5c; }
@media (prefers-color-scheme: dark) {
  .rar-C, .rar-U, .rar-R, .rar-S, .rar-L, .rar-Ep { filter: brightness(.85); }
}
.ink { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; vertical-align: middle; flex: none; }

/* saisie */
.saisie-grid { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 16px; align-items: start; }
.saisie-grid > * { min-width: 0; }
.entry input { min-width: 0; }
#grid, #rList .search-set { overflow-x: auto; }
@media (max-width: 900px) { .saisie-grid { grid-template-columns: 1fr; } }
.entry { display: flex; gap: 8px; }
.entry input { flex: 1; font-size: 18px; padding: 10px 14px; }
.preview { min-height: 24px; margin-top: 8px; color: var(--muted); }
.suggestions { list-style: none; margin: 6px 0 0; padding: 0; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.suggestions li { padding: 6px 10px; cursor: pointer; display: flex; gap: 8px; align-items: center; }
.suggestions li:hover, .suggestions li.sel { background: var(--accent-soft); }
.log { list-style: none; margin: 0; padding: 0; max-height: 70vh; overflow: auto; }
.log li { display: flex; gap: 10px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); }
.log img { width: 46px; border-radius: 4px; flex: none; }
.log .info { flex: 1; min-width: 0; }
.log .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tag { display: inline-block; font-size: 11px; font-weight: 700; padding: 1px 7px; border-radius: 999px; }
.tag.ok { background: var(--ok-soft); color: var(--ok); }
.tag.warn { background: var(--warn-soft); color: var(--warn); }
.tag.bad { background: var(--bad-soft); color: var(--bad); }
.tag.neutral { background: var(--accent-soft); color: var(--accent); }

.progress { height: 8px; background: var(--line); border-radius: 999px; overflow: hidden; }
.progress > div { height: 100%; background: var(--ok); border-radius: 999px; }
.progress.gold > div { background: var(--gold); }

table.cards { width: 100%; border-collapse: collapse; }
table.cards th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: 6px 8px; border-bottom: 1px solid var(--line); }
table.cards td { padding: 5px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.cards td.num { color: var(--muted); width: 48px; text-align: right; }
table.cards tr.complete td.name { color: var(--muted); }
table.cards tr.missing td.qty .q { color: var(--bad); font-weight: 700; }
table.cards tr.partial td.qty .q { color: var(--warn); font-weight: 700; }
.qty { white-space: nowrap; width: 120px; }
.qty .q { display: inline-block; min-width: 38px; text-align: center; }
.qty button { width: 26px; height: 26px; border-radius: 6px; border: 1px solid var(--line); background: var(--panel); cursor: pointer; line-height: 1; }
.qty button:hover { border-color: var(--accent); }
.name-cell { display: flex; align-items: center; }
.hover-img { position: fixed; z-index: 50; width: 220px; border-radius: 10px; box-shadow: 0 8px 30px rgba(0,0,0,.35); pointer-events: none; }

/* recherche */
.search-set { margin-bottom: 18px; }
.search-set h3 { display: flex; justify-content: space-between; align-items: baseline; margin-top: 0; }
.need { font-weight: 700; color: var(--bad); white-space: nowrap; }

/* collection */
.sets { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.set-card { cursor: pointer; }
.set-card:hover { border-color: var(--accent); }
.set-card .row { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); margin: 8px 0 4px; }
.stats { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.stat { flex: 1; min-width: 160px; }
.stat .v { font-size: 24px; font-weight: 700; }

/* tuiles promos / goodies */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.tile {
  position: relative; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 8px; cursor: pointer; display: flex; flex-direction: column; gap: 4px; transition: opacity .15s;
}
.tile:hover { border-color: var(--accent); }
.tile .img { aspect-ratio: 5 / 7; background: var(--bg); border-radius: 6px; overflow: hidden; display: grid; place-items: center; color: var(--muted); font-size: 28px; }
.tile.square .img { aspect-ratio: 1; }
.tile .img img { width: 100%; height: 100%; object-fit: cover; }
.tile.not-owned .img img { filter: grayscale(1); opacity: .45; }
.tile.not-owned .t-name { color: var(--muted); }
.tile .t-name { font-weight: 600; font-size: 12.5px; line-height: 1.25; }
.tile .t-sub { font-size: 11px; color: var(--muted); line-height: 1.25; }
.tile .check {
  position: absolute; top: 12px; right: 12px; width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center;
  font-weight: 700; background: var(--panel); border: 2px solid var(--line); color: transparent;
}
.tile.owned .check { background: var(--ok); border-color: var(--ok); color: #fff; }
.tile .actions { display: flex; gap: 4px; flex-wrap: wrap; margin-top: auto; }
.group-head { display: flex; align-items: baseline; gap: 10px; margin: 24px 0 10px; }
.group-head h3 { margin: 0; }

.goodie-list { display: flex; flex-direction: column; gap: 6px; }
.goodie {
  display: flex; align-items: center; gap: 12px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 12px;
}
.goodie img, .goodie .noimg { width: 56px; height: 56px; object-fit: cover; border-radius: 6px; flex: none; background: var(--bg); display: grid; place-items: center; color: var(--muted); }
.goodie .info { flex: 1; min-width: 0; }
.goodie .g-name { font-weight: 600; }
.goodie.not-owned .g-name { color: var(--muted); }
.goodie.not-owned img { filter: grayscale(1); opacity: .5; }
.toggle {
  border: 2px solid var(--line); background: var(--panel); border-radius: 999px; padding: 4px 12px; cursor: pointer; font-weight: 600; font-size: 12px; white-space: nowrap;
}
.toggle.on { background: var(--ok); border-color: var(--ok); color: #fff; }

.empty { padding: 30px; text-align: center; color: var(--muted); }

#toasts { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 100; }
.toast { background: var(--ink); color: var(--bg); padding: 10px 14px; border-radius: 8px; box-shadow: 0 4px 16px rgba(0,0,0,.2); max-width: 420px; }
.toast.error { background: var(--bad); color: #fff; }

dialog { border: 1px solid var(--line); border-radius: 12px; padding: 0; background: var(--panel); color: var(--ink); width: min(620px, 94vw); max-height: 92vh; }
dialog::backdrop { background: rgba(0,0,0,.35); }
dialog form { padding: 18px; display: flex; flex-direction: column; gap: 10px; }
dialog label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
dialog label.inline { flex-direction: row; align-items: center; gap: 8px; color: var(--ink); font-size: 14px; }
/* ordre HTML : Enregistrer, Annuler, Supprimer (Entrée = Enregistrer) ; affichage inversé */
dialog .buttons { display: flex; flex-direction: row-reverse; justify-content: flex-start; gap: 8px; margin-top: 6px; }
dialog .buttons .danger { margin-right: auto; }

.img-picker { border: 1px solid var(--line); border-radius: 8px; padding: 10px; display: flex; flex-direction: column; gap: 8px; margin: 0; }
.img-picker legend { font-size: 12px; color: var(--muted); padding: 0 4px; }
.img-current { display: flex; gap: 10px; align-items: center; }
.img-current .thumb { width: 64px; height: 64px; flex: none; border-radius: 6px; background: var(--bg); display: grid; place-items: center; overflow: hidden; color: var(--muted); }
.img-current .thumb img { width: 100%; height: 100%; object-fit: contain; }
.img-fields { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.img-fields input { width: 100%; }
.img-search input { font-size: 14px; padding: 7px 10px; }
.img-results { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; max-height: 300px; overflow: auto; }
.img-results > .small { grid-column: 1 / -1; }
.img-hit {
  display: flex; flex-direction: column; gap: 2px; padding: 4px; border: 2px solid var(--line); border-radius: 8px;
  background: var(--panel); cursor: pointer; text-align: left; font-size: 10.5px; line-height: 1.2;
}
.img-hit:hover { border-color: var(--accent); }
.img-hit.active { border-color: var(--ok); }
.img-hit img { width: 100%; aspect-ratio: 1; object-fit: contain; background: var(--bg); border-radius: 4px; }
.img-hit span { overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.tile .img { position: relative; }
.tile .approx { position: absolute; left: 6px; bottom: 6px; font-size: 10px; font-weight: 700; padding: 1px 6px; border-radius: 999px; background: rgba(0,0,0,.65); color: #fff; }

/* connexion (version en ligne) */
.login { max-width: 360px; margin: 12vh auto 0; display: flex; flex-direction: column; gap: 12px; }
.login input[type=password] { font-size: 16px; padding: 10px 12px; }
.login .btn { padding: 10px; }
.login-error { color: var(--bad); min-height: 1.2em; margin: 0; }

/* téléphone */
@media (max-width: 700px) {
  .topbar { flex-wrap: wrap; gap: 6px 12px; padding: 8px 12px; }
  .tabs { order: 3; width: 100%; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .tabs button { padding: 6px 12px; white-space: nowrap; }
  .save-status { white-space: normal; text-align: right; }
  main { padding: 14px 12px 60px; }
  input[type=text], input[type=search], input[type=number], input[type=url], select { font-size: 16px; } /* évite le zoom iOS */
  .toolbar > input[type=search], .toolbar > select { flex: 1 1 100%; }
  .tiles { grid-template-columns: repeat(auto-fill, minmax(105px, 1fr)); gap: 8px; }
  .tile .check { top: 8px; right: 8px; }
  table.cards td { padding: 6px 4px; }
  table.cards td.num { width: 34px; }
  table.cards th:nth-child(3), table.cards td:nth-child(3) { padding: 6px 2px; }
  .panel { padding: 12px; }
  .entry input { font-size: 16px; padding: 10px; }
  .qty { width: auto; }
  .qty button { width: 36px; height: 36px; font-size: 18px; }
  .goodie { flex-wrap: wrap; }
  .goodie .info { flex-basis: calc(100% - 70px); }
  .hover-img { display: none; }
  #toasts { left: 12px; right: 12px; bottom: 12px; }
}

@media print {
  .topbar, .toolbar, #toasts, .no-print { display: none !important; }
  main { padding: 0; max-width: none; }
  body { background: #fff; color: #000; }
  .search-set { break-inside: avoid-page; }
}

/* vente */
.vente-table { overflow-x: auto; padding: 8px 12px; }
.vente-table select { padding: 4px 6px; }
.vente-table td.price, .vente-table th.price { text-align: right; white-space: nowrap; }
.vente-table input[data-price] { width: 80px; text-align: right; padding: 4px 8px; }
.vente-table th.sel, .vente-table td.sel { width: 28px; padding-right: 0; }
.vente-table input[type=checkbox] { width: 16px; height: 16px; margin: 0; cursor: pointer; accent-color: var(--accent); }
.vente-table tr.selected td { background: var(--accent-soft); }
.sel-stat .btn.small { padding: 0 4px; margin-left: 4px; }
