:root {
  --bg: #0e1319;
  --panel: #141a24;
  --panel2: #1b2331;
  --text: #e8edf4;
  --muted: #8b98ab;
  --accent: #4da3ff;
  --ok: #3ecf8e;
  --warn: #ffb454;
  --danger: #ff6b6b;
  --radius: 14px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: flex;
  flex-direction: column;
  padding-bottom: env(safe-area-inset-bottom);
}
#topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; background: var(--panel);
  position: sticky; top: 0; z-index: 5;
}
#topbar h1 { margin: 0; font-size: 1.15rem; }
main { flex: 1; padding: 14px; max-width: 900px; width: 100%; margin: 0 auto; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: .82rem; }
.row { display: flex; gap: 8px; margin: 10px 0; }
.row input, .row select {
  flex: 1; min-width: 0; padding: 11px 12px; border-radius: var(--radius);
  border: 1px solid #2a3547; background: var(--panel2); color: var(--text); font-size: 1rem;
}
button {
  padding: 11px 16px; border: none; border-radius: var(--radius);
  background: var(--panel2); color: var(--text); font-size: 1rem; cursor: pointer;
}
button.primary { background: var(--accent); color: #06121f; font-weight: 600; }
button.danger { background: var(--danger); color: #1c0606; font-weight: 600; }
button:active { transform: scale(.97); }

/* Scanner */
#scan-box {
  position: relative; border-radius: var(--radius); overflow: hidden;
  background: #000; aspect-ratio: 4/3; max-height: 45vh; margin: 0 auto;
}
#preview { width: 100%; height: 100%; object-fit: cover; }
#scan-line {
  position: absolute; left: 8%; right: 8%; top: 50%; height: 2px;
  background: var(--danger); box-shadow: 0 0 8px var(--danger); opacity: .8;
}
#scan-hint {
  position: absolute; bottom: 8px; left: 0; right: 0; text-align: center;
  font-size: .85rem; color: #fff; text-shadow: 0 1px 3px #000;
}

/* Carte résultat de scan */
.book-card {
  display: flex; gap: 14px; background: var(--panel); border-radius: var(--radius);
  padding: 14px; margin-top: 12px;
}
.book-card img.cover, .tile img.cover {
  width: 92px; height: 138px; object-fit: cover; border-radius: 8px;
  background: var(--panel2); flex-shrink: 0;
}
.book-card .info { flex: 1; min-width: 0; }
.book-card h3 { margin: 0 0 4px; font-size: 1.05rem; }
.badge {
  display: inline-block; padding: 3px 9px; border-radius: 20px;
  font-size: .78rem; background: var(--panel2); margin: 2px 4px 2px 0;
}
.badge.price { background: #1d3a2c; color: var(--ok); font-weight: 600; }
.badge.warn { background: #3a2d1d; color: var(--warn); }

/* Grille bibliothèque */
#grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 12px; margin-top: 12px;
}
.tile { cursor: pointer; text-align: center; }
.tile img.cover { width: 100%; height: 160px; }
.tile .t-title {
  font-size: .8rem; margin-top: 6px; overflow: hidden; display: -webkit-box;
  -webkit-line-clamp: 2; -webkit-box-orient: vertical;
}
.tile .t-price { font-size: .78rem; color: var(--ok); }

/* Stats */
#stats-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; }
.stat {
  background: var(--panel); border-radius: var(--radius); padding: 16px; text-align: center;
}
.stat .v { font-size: 1.7rem; font-weight: 700; color: var(--accent); }
.stat .l { color: var(--muted); font-size: .85rem; margin-top: 4px; }

/* Modale */
#modal {
  position: fixed; inset: 0; background: rgba(0,0,0,.65); z-index: 20;
  display: flex; align-items: flex-end; justify-content: center;
}
#modal-card {
  background: var(--panel); width: 100%; max-width: 640px; max-height: 88vh;
  overflow-y: auto; border-radius: var(--radius) var(--radius) 0 0; padding: 18px;
}
@media (min-width: 700px) {
  #modal { align-items: center; }
  #modal-card { border-radius: var(--radius); }
}
#modal-card .head { display: flex; gap: 14px; }
#modal-card textarea {
  width: 100%; min-height: 70px; background: var(--panel2); color: var(--text);
  border: 1px solid #2a3547; border-radius: 8px; padding: 10px; font-size: .95rem;
}
#modal-card .desc { font-size: .92rem; line-height: 1.5; color: #c6d0dd; }
#modal-card .actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }

/* Onglets bas */
#tabs {
  display: flex; background: var(--panel); position: sticky; bottom: 0; z-index: 5;
  padding-bottom: env(safe-area-inset-bottom);
}
#tabs button {
  flex: 1; background: none; border-radius: 0; display: flex; flex-direction: column;
  align-items: center; gap: 2px; font-size: 1.25rem; padding: 8px 0 6px; color: var(--muted);
}
#tabs button span { font-size: .7rem; }
#tabs button.active { color: var(--accent); }

/* Séries */
.series-card {
  background: var(--panel); border-radius: var(--radius); padding: 14px; margin: 10px 0;
}
.series-card .s-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.series-card .s-head b { font-size: 1.02rem; }
.badge.complete { background: #1d3a2c; color: var(--ok); font-weight: 600; }
.progress {
  height: 8px; background: var(--panel2); border-radius: 6px; overflow: hidden; margin: 8px 0 6px;
}
.progress i { display: block; height: 100%; background: var(--accent); border-radius: 6px; }
.s-books { display: flex; gap: 8px; overflow-x: auto; padding: 6px 0; }
.s-tome {
  flex-shrink: 0; width: 56px; text-align: center; cursor: pointer; font-size: .72rem;
  color: var(--muted);
}
.s-tome img {
  width: 56px; height: 82px; object-fit: cover; border-radius: 6px; background: var(--panel2);
  display: block; margin-bottom: 2px;
}
.s-tome.wish { opacity: .55; }
.series-card .s-actions { display: flex; gap: 8px; margin-top: 6px; }
.small-btn { padding: 7px 12px; font-size: .85rem; }
#modal-card select {
  flex: 1; min-width: 0; padding: 11px 12px; border-radius: var(--radius);
  border: 1px solid #2a3547; background: var(--panel2); color: var(--text); font-size: 1rem;
}

/* Grille de tomes d'une série */
.s-more-box {
  width: 56px; height: 82px; border-radius: 6px; background: var(--panel2);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; color: var(--accent); margin-bottom: 2px;
}
.tome-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(88px, 1fr));
  gap: 10px; max-height: 62vh; overflow-y: auto; padding: 4px 0;
}
.tg-tile { cursor: pointer; text-align: center; }
.tg-tile img, .tg-ph {
  width: 100%; aspect-ratio: 2/3; object-fit: cover; border-radius: 8px;
  background: var(--panel2); display: block;
}
.tg-num { display: block; font-size: .78rem; font-weight: 700; color: var(--accent); margin-bottom: 3px; }
.tg-t {
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  font-size: .72rem; color: var(--muted); margin-top: 3px;
}
.tg-tile.wish { opacity: .55; }
.tg-tile:active { transform: scale(.96); }

/* Auto-complétion de série */
#dv-list { max-height: 46vh; overflow-y: auto; border-radius: 8px; }
.dv-row {
  display: flex; align-items: center; gap: 10px; padding: 7px 8px;
  border-bottom: 1px solid #202a3a; cursor: pointer; font-size: .92rem;
}
.dv-row.have { opacity: .45; }
.dv-row input { width: 18px; height: 18px; flex-shrink: 0; }
.dv-check { color: var(--ok); width: 18px; text-align: center; flex-shrink: 0; }
.dv-num { color: var(--accent); font-weight: 600; width: 44px; flex-shrink: 0; }
.dv-title { flex: 1; min-width: 0; }
.dv-title .muted { display: block; }

/* Connexion */
#login-form {
  max-width: 360px; margin: 12vh auto 0; background: var(--panel);
  border-radius: var(--radius); padding: 22px;
}
#login-form h2 { margin: 0 0 14px; text-align: center; }

/* Comptes (admin) */
.user-row {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--panel); border-radius: var(--radius); padding: 10px 14px; margin: 8px 0;
}
.user-row .u-actions { display: flex; gap: 6px; }
.user-row .u-actions button { padding: 8px 12px; }
label.check {
  display: flex; align-items: center; gap: 8px; color: var(--muted);
  padding: 11px 4px; font-size: .95rem; flex: 1;
}
#topbar #btn-account { padding: 7px 12px; font-size: .9rem; background: var(--panel2); }

/* Toast */
#toast {
  position: fixed; bottom: 76px; left: 50%; transform: translateX(-50%);
  background: var(--panel2); border: 1px solid #2a3547; color: var(--text);
  padding: 10px 18px; border-radius: 24px; z-index: 30; font-size: .92rem;
  box-shadow: 0 4px 18px rgba(0,0,0,.5); max-width: 88vw;
}
.spinner {
  display: inline-block; width: 16px; height: 16px; vertical-align: -3px;
  border: 2px solid var(--muted); border-top-color: var(--accent);
  border-radius: 50%; animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
