:root {
  --bg: #f6f4ef;
  --surface: #ffffff;
  --ink: #1e1d1a;
  --muted: #666157;
  --accent: #7a2e22;
  --accent-soft: #f3e8e5;
  --border: #e2ddd2;
  --shadow: 0 6px 20px rgba(30, 29, 26, 0.06);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.55;
}

header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 1.1rem 2rem;
  position: sticky;
  top: 0;
  z-index: 10;
}

.header-inner {
  max-width: 1240px;
  margin: 0 auto;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

h1 {
  margin: 0;
  font-size: 1.65rem;
  letter-spacing: 0.02em;
}

.subtitle {
  font-size: 0.9rem;
  color: var(--muted);
  font-style: italic;
}

.actions {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
  align-items: center;
}

button, select {
  font-family: inherit;
  cursor: pointer;
  border-radius: 6px;
  padding: 0.48rem 0.85rem;
  font-size: 0.9rem;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink);
  transition: all 0.15s ease;
}

button:hover:not(:disabled), select:hover { border-color: var(--ink); }
button:disabled { opacity: 0.5; cursor: not-allowed; }

button.primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

button.primary:hover:not(:disabled) { opacity: 0.92; }
button.small { padding: 0.28rem 0.58rem; font-size: 0.8rem; }

.status-badge {
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 0.8rem;
  padding: 0.3rem 0.65rem;
  border-radius: 999px;
  background: #ece8df;
  color: var(--muted);
}

main {
  max-width: 1240px;
  margin: 1.5rem auto;
  padding: 0 1.5rem 4rem;
}

.tabs {
  display: flex;
  gap: 0.5rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1.4rem;
  padding-bottom: 0.6rem;
  flex-wrap: wrap;
}

.tab-btn {
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 0.9rem;
  font-weight: 600;
  border-radius: 8px;
  padding: 0.5rem 1rem;
}

.tab-btn.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 1.4rem;
  align-items: center;
}

input[type="text"], textarea, input[type="password"], input[type="number"] {
  font-family: system-ui, -apple-system, sans-serif;
  padding: 0.55rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.92rem;
  background: #fff;
  color: var(--ink);
  width: 100%;
}

.search-box { flex: 1; min-width: 220px; }

.filter-select {
  min-width: 165px;
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 0.86rem;
}

/* Fiches livres */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(330px, 1fr));
  gap: 1.5rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.card-top {
  display: flex;
  gap: 1rem;
  padding: 1.1rem;
  border-bottom: 1px solid var(--border);
  background: #fcfbf8;
}

.cover {
  width: 78px;
  height: 114px;
  object-fit: cover;
  border-radius: 4px;
  border: 1px solid var(--border);
  flex-shrink: 0;
  background: #e9e4d8;
}

.cover-fallback {
  width: 78px;
  height: 114px;
  border-radius: 4px;
  border: 1px solid #c9bfa9;
  background: linear-gradient(145deg, #2d2620, #4a3c31);
  color: #f4efe6;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 0.4rem;
  font-size: 0.72rem;
  flex-shrink: 0;
}

.meta h2 {
  margin: 0 0 0.25rem;
  font-size: 1.12rem;
  line-height: 1.3;
}

.author {
  color: var(--muted);
  font-size: 0.9rem;
  margin-bottom: 0.35rem;
}

.status-line {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 0.4rem;
}

.shelf-pill {
  display: inline-block;
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 0.72rem;
  padding: 0.14rem 0.55rem;
  border-radius: 999px;
  background: #efece4;
  color: var(--muted);
}

.unread-pill {
  display: inline-block;
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 0.14rem 0.55rem;
  border-radius: 999px;
  background: #e8eef5;
  color: #23425c;
}

.stars-text {
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 0.82rem;
  color: #8a5216;
  font-weight: 600;
}

.keywords {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.kw {
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 0.73rem;
  background: var(--accent-soft);
  color: var(--accent);
  padding: 0.16rem 0.52rem;
  border-radius: 4px;
  font-weight: 600;
}

.card-body {
  padding: 1.1rem;
  font-size: 0.92rem;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
}

.label { font-weight: bold; color: var(--ink); }

.avis-box {
  background: #f9f7f2;
  border-left: 3px solid var(--accent);
  padding: 0.55rem 0.75rem;
  font-style: italic;
  font-size: 0.88rem;
}

.card-footer {
  padding: 0.72rem 1.1rem;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.card-footer-right { display: flex; gap: 0.45rem; }

/* Bibliothèques horizontales (menu roulant) */
.shelves-topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.shelves-scroll-controls {
  display: flex;
  gap: 0.4rem;
  align-items: center;
}

.libraries-strip {
  display: flex;
  flex-direction: row;
  gap: 1.5rem;
  overflow-x: auto;
  scroll-snap-type: x proximity;
  padding-bottom: 1rem;
  align-items: flex-start;
}

.library-cabinet {
  flex: 0 0 470px;
  max-width: 92vw;
  scroll-snap-align: start;
  background: #efe9dc;
  border: 1px solid #d4cbb8;
  border-radius: 12px;
  padding: 1.1rem 1.2rem 1.3rem;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.library-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.library-title-wrap {
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.library-title {
  margin: 0;
  font-size: 1.15rem;
  cursor: pointer;
}

.library-meta {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex-wrap: wrap;
}

.library-count {
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 0.78rem;
  background: var(--accent-soft);
  color: var(--accent);
  padding: 0.18rem 0.55rem;
  border-radius: 999px;
  font-weight: 700;
}

.shelf-unit { display: flex; flex-direction: column; }

.shelf-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
  margin-bottom: 0.3rem;
}

.shelf-label {
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
}

.shelf-controls {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  flex-wrap: wrap;
}

.shelf-stage {
  background: linear-gradient(180deg, #3c3026 0%, #2a211a 100%);
  border-radius: 8px 8px 0 0;
  padding: 0.9rem 0.85rem 0;
  min-height: 210px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  overflow-x: auto;
  box-shadow: inset 0 6px 14px rgba(0, 0, 0, 0.35);
  border: 2px solid transparent;
  transition: border-color 0.15s ease;
}

.shelf-stage.drag-over { border-color: #f0c987; }

.spines-row {
  display: flex;
  align-items: flex-end;
  gap: 5px;
  min-height: 192px;
  padding-bottom: 2px;
}

.book-spine {
  position: relative;
  width: 48px;
  height: 188px;
  border-radius: 3px 5px 3px 2px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: center;
  padding: 8px 4px;
  cursor: grab;
  user-select: none;
  flex-shrink: 0;
  box-shadow:
    inset 3px 0 5px rgba(255, 255, 255, 0.14),
    inset -3px 0 6px rgba(0, 0, 0, 0.45),
    2px 3px 6px rgba(0, 0, 0, 0.35);
  border-top: 1px solid rgba(255, 255, 255, 0.18);
  border-bottom: 1px solid rgba(0, 0, 0, 0.5);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.book-spine:hover { transform: translateY(-9px); z-index: 2; }
.book-spine.selected { transform: translateY(-11px); outline: 2px solid #f0c987; }
.book-spine:active { cursor: grabbing; }

.spine-band {
  width: 82%;
  height: 4px;
  border-radius: 2px;
  background: rgba(245, 224, 178, 0.55);
  flex-shrink: 0;
}

.spine-title {
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 0.75rem;
  font-weight: bold;
  letter-spacing: 0.02em;
  color: #fbf7ef;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.75);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-height: 112px;
  line-height: 1.1;
}

.spine-author {
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 0.62rem;
  color: rgba(251, 247, 239, 0.82);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.75);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-height: 46px;
}

.wooden-plank {
  height: 15px;
  background: linear-gradient(180deg, #8b5a2b 0%, #6d431d 55%, #4f2f12 100%);
  border-radius: 0 0 6px 6px;
  border-top: 1px solid #a9733f;
  box-shadow: 0 5px 10px rgba(0, 0, 0, 0.25);
}

.shelf-empty {
  color: rgba(251, 247, 239, 0.72);
  font-style: italic;
  font-size: 0.86rem;
  padding: 2rem 0.5rem;
  text-align: center;
  width: 100%;
}

.inspector-bar {
  margin-top: 1.3rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem 1.25rem;
  box-shadow: var(--shadow);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 1rem;
}

.inspector-empty { color: var(--muted); font-style: italic; font-size: 0.92rem; }
.inspector-actions { display: flex; gap: 0.45rem; flex-wrap: wrap; align-items: center; }

/* Vitrine (3 étagères non modifiables) */
.vitrine-stack {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.vitrine-shelf {
  background: #efe9dc;
  border: 1px solid #d4cbb8;
  border-radius: 12px;
  padding: 1rem 1.2rem 1.2rem;
  box-shadow: var(--shadow);
}

.vitrine-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.6rem;
}

.vitrine-title { margin: 0; font-size: 1.15rem; }

/* Modales & champs */
dialog {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0;
  max-width: 590px;
  width: 92%;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.2);
}

dialog::backdrop { background: rgba(20, 18, 15, 0.5); }

.modal-head {
  padding: 1.05rem 1.4rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-body {
  padding: 1.2rem 1.4rem;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.field label {
  display: block;
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 0.84rem;
  font-weight: 600;
  margin-bottom: 0.3rem;
}

.row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.row-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.65rem;
}

.inline-add {
  display: flex;
  gap: 0.4rem;
  margin-top: 0.35rem;
}

.check-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.8rem;
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 0.86rem;
}

.check-row label {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-weight: 500;
  margin: 0;
  cursor: pointer;
}

.rating-controls {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  flex-wrap: wrap;
}

.modal-foot {
  padding: 1rem 1.4rem;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 0.6rem;
}