:root {
  --bg: #f7f4ee;
  --surface: #ffffff;
  --surface-2: #efeae0;
  --text: #22201c;
  --muted: #6f685c;
  --border: #ddd5c6;
  --accent: #b4532a;
  --accent-text: #ffffff;
  --accent-soft: #f4e2d8;
  --danger: #b3261e;
  --ok-bg: #e5f2e6; --ok-text: #1f5a2b;
  --err-bg: #fbe4e2; --err-text: #8a1f17;
  --info-bg: #e7eef6; --info-text: #234a6b;
  --shadow: 0 1px 2px rgb(0 0 0 / .06), 0 4px 14px rgb(0 0 0 / .06);
  --radius: 10px;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1a1916; --surface: #24221e; --surface-2: #2e2b26; --text: #ece7de; --muted: #a59d8f;
    --border: #3b3731; --accent: #e07a4f; --accent-text: #1a1916; --accent-soft: #3b2a21;
    --danger: #ef6b62; --ok-bg: #1e3322; --ok-text: #a8dcb1; --err-bg: #3d1f1c; --err-text: #f4b3ad;
    --info-bg: #1d2a37; --info-text: #b4d0ea; --shadow: 0 1px 2px rgb(0 0 0 / .4), 0 4px 14px rgb(0 0 0 / .3);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.5 var(--sans); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { font-family: var(--serif); font-weight: 600; line-height: 1.2; margin: 0 0 .4em; }
h1 { font-size: 1.9rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: .8rem; font-family: var(--sans); text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.muted { color: var(--muted); }
.small, small { font-size: .85rem; }
.container { max-width: 1240px; margin: 0 auto; padding: 24px 16px 64px; }
.narrow { max-width: 460px; }

/* Barre du haut */
.topbar { background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20; }
.topbar-inner { max-width: 1240px; margin: 0 auto; padding: 10px 16px; display: flex; gap: 16px; align-items: center; flex-wrap: wrap; }
.brand { font-family: var(--serif); font-size: 1.3rem; font-weight: 700; color: var(--text); }
.brand::before { content: ""; display: inline-block; width: 14px; height: 18px; margin-right: 8px; vertical-align: -2px;
  background: linear-gradient(90deg, var(--accent) 0 30%, transparent 30% 38%, #395b64 38% 68%, transparent 68% 76%, #a77b2c 76%); border-radius: 2px; }
.brand:hover { text-decoration: none; }
.brand-lg { font-size: 2rem; text-align: center; margin-bottom: 24px; }
.topsearch { flex: 1 1 280px; max-width: 520px; }
.mainnav { display: flex; gap: 4px; align-items: center; margin-left: auto; flex-wrap: wrap; }
.mainnav a:not(.btn) { color: var(--muted); padding: 6px 10px; border-radius: 6px; }
.mainnav a:not(.btn):hover, .mainnav a[aria-current] { color: var(--text); background: var(--surface-2); text-decoration: none; }

/* Formulaires */
input, select, textarea { font: inherit; color: inherit; background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 10px; width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
input[type=checkbox] { width: auto; }
input[type=file] { padding: 6px; }
label { display: flex; flex-direction: column; gap: 4px; font-weight: 500; font-size: .9rem; }
label.check { flex-direction: row; align-items: center; gap: 8px; font-weight: 400; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 8px 14px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); font: inherit; font-weight: 500; cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn-primary:hover { background: var(--accent); filter: brightness(1.08); }
.btn-danger { color: var(--danger); }
.btn-small { padding: 4px 10px; font-size: .85rem; }
.linklike { background: none; border: 0; padding: 0; color: var(--accent); font: inherit; cursor: pointer; }
.linklike:hover { text-decoration: underline; }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.stack { display: flex; flex-direction: column; gap: 14px; }
.inline-form { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; margin: 16px 0; }
.inline-form label { flex: 1 1 180px; }
.actions { display: flex; gap: 10px; margin-top: 20px; flex-wrap: wrap; }
.row { display: flex; gap: 6px; }

.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 16px; }
.flash ul { margin: 0; padding-left: 18px; }
.flash-success { background: var(--ok-bg); color: var(--ok-text); }
.flash-error { background: var(--err-bg); color: var(--err-text); }
.flash-info { background: var(--info-bg); color: var(--info-text); }
.badge { display: inline-block; font-size: .75rem; padding: 1px 8px; border-radius: 99px; background: var(--surface-2); color: var(--muted); }
.empty { text-align: center; padding: 48px 16px; color: var(--muted); }
.page-head { display: flex; align-items: baseline; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head h1 { margin: 0; }

.auth { max-width: 380px; margin: 10vh auto 0; }

/* Couvertures */
.cover { display: block; width: 100%; aspect-ratio: 2 / 3; object-fit: cover; border-radius: 4px; background: var(--surface-2);
  box-shadow: 0 1px 2px rgb(0 0 0 / .15), 2px 3px 8px rgb(0 0 0 / .12); }
.cover-blank { display: flex; align-items: center; justify-content: center; padding: 10px; text-align: center;
  font-family: var(--serif); font-size: .85rem; color: var(--muted); overflow: hidden;
  background: linear-gradient(160deg, var(--surface-2), var(--border)); }
.cover-blank span { display: -webkit-box; -webkit-line-clamp: 5; -webkit-box-orient: vertical; overflow: hidden; }
.cover-lg { max-width: 280px; }

/* Rayonnages */
.shelves { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 18px; margin-bottom: 24px; }
.shelf { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 16px 0; color: inherit; box-shadow: var(--shadow); transition: transform .15s; }
.shelf:hover { text-decoration: none; transform: translateY(-2px); }
.shelf-head { display: flex; justify-content: space-between; align-items: baseline; }
.shelf-head h2 { margin: 0; }
.count { color: var(--muted); font-size: .9rem; }
.shelf-row { display: flex; gap: 8px; align-items: flex-end; min-height: 110px; padding: 14px 0 10px; border-bottom: 8px solid var(--surface-2); overflow: hidden; }
.shelf-row .cover { width: 62px; flex: none; }

/* Liste */
.layout { display: grid; grid-template-columns: 240px 1fr; gap: 28px; align-items: start; }
.filters section { margin-bottom: 20px; }
.filters-toggle > summary { display: none; }
.facet { list-style: none; margin: 0; padding: 0; }
.facet a { display: flex; justify-content: space-between; gap: 8px; padding: 3px 8px; border-radius: 6px; color: var(--text); font-size: .9rem; }
.facet a span { color: var(--muted); font-size: .8rem; }
.facet a:hover { background: var(--surface-2); text-decoration: none; }
.facet a.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.more summary { cursor: pointer; color: var(--accent); font-size: .85rem; padding: 3px 8px; }
.years { display: flex; gap: 6px; align-items: center; }
.years input { width: 72px; padding: 6px 8px; }
.toolbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { background: var(--accent-soft); color: var(--accent); padding: 3px 10px; border-radius: 99px; font-size: .85rem; }
.sort label { flex-direction: row; align-items: center; gap: 8px; font-weight: 400; color: var(--muted); }
.sort select { width: auto; padding: 5px 8px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 24px 18px; }
.card { display: flex; flex-direction: column; gap: 4px; color: inherit; }
.card:hover { text-decoration: none; }
.card:hover .cover { transform: translateY(-3px); }
.card .cover { transition: transform .15s; margin-bottom: 6px; }
.card-title { font-weight: 600; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card-meta { color: var(--muted); font-size: .82rem; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.pager { display: flex; justify-content: center; gap: 20px; margin-top: 32px; align-items: center; }

/* Fiche */
.book { display: grid; grid-template-columns: 280px 1fr; gap: 40px; align-items: start; }
.crumbs { margin: 0 0 6px; font-size: .9rem; }
.subtitle { font-family: var(--serif); font-size: 1.2rem; color: var(--muted); margin: -4px 0 8px; }
.authors { font-size: 1.1rem; margin: 0 0 20px; }
.meta { display: grid; grid-template-columns: max-content 1fr; gap: 6px 20px; margin: 0 0 20px; }
.meta dt { color: var(--muted); }
.meta dd { margin: 0; }
.description { white-space: pre-line; max-width: 70ch; line-height: 1.65; }

/* Ajout */
.addsearch { display: flex; gap: 10px; max-width: 640px; margin-bottom: 20px; }
.candidates { list-style: none; padding: 0; margin: 0 0 20px; display: flex; flex-direction: column; gap: 10px; }
.candidate { display: grid; grid-template-columns: 56px 1fr auto; gap: 16px; align-items: center; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 14px; }
.candidate.is-owned { opacity: .65; }
.candidate .cover { width: 56px; }
.candidate .badge { margin-left: 6px; }
.manual { margin-top: 12px; }
.bookform { display: grid; grid-template-columns: 240px 1fr; gap: 32px; align-items: start; }
.bookform-cover { display: flex; flex-direction: column; gap: 12px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.span2 { grid-column: span 2; }

/* Admin */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; }
.tabs a { padding: 8px 14px; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs a[aria-current] { color: var(--text); border-color: var(--accent); }
.tabs a:hover { text-decoration: none; color: var(--text); }
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.table th, .table td { text-align: left; padding: 8px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table th { font-size: .8rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; }
.table select { width: auto; }
.genre-row { display: grid; grid-template-columns: 64px minmax(140px, 1fr) minmax(200px, 2.5fr) auto; gap: 8px; }
.w-pos { width: 64px; }

/* Autocomplétion */
.suggest-wrap { position: relative; }
.suggest { position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 30; list-style: none; margin: 0; padding: 4px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); max-height: 70vh; overflow-y: auto; }
.suggest li { display: flex; gap: 10px; align-items: center; padding: 6px 8px; border-radius: 6px; cursor: pointer; }
.suggest li[aria-selected=true], .suggest li:hover { background: var(--surface-2); }
.suggest img, .suggest .ph { width: 28px; height: 42px; object-fit: cover; border-radius: 2px; flex: none; background: var(--surface-2); }
.suggest .ph.author { height: 28px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: .8rem; color: var(--muted); }
.suggest .label { font-weight: 500; }
.suggest .sub { font-size: .8rem; color: var(--muted); }
.suggest mark { background: none; color: var(--accent); font-weight: 700; }

@media (max-width: 860px) {
  .layout, .book, .bookform { grid-template-columns: 1fr; }
  .filters-toggle > summary { display: block; cursor: pointer; font-weight: 600; padding: 8px 0; }
  .filters-toggle:not([open]) { margin-bottom: 8px; }
  .cover-lg { max-width: 200px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); }
  .grid2 { grid-template-columns: 1fr; }
  .span2 { grid-column: auto; }
  .candidate { grid-template-columns: 48px 1fr; }
  .candidate > form, .candidate > .btn { grid-column: 1 / -1; }
  .shelves { grid-template-columns: 1fr; }
  .genre-row { grid-template-columns: 56px 1fr; }
  .mainnav { margin-left: 0; }
}
