/* =============================================
   Ma Bibliothèque — SG Créations
   Palette : vert forêt / sauge
   ============================================= */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:          #F0F5F1;
  --surface:     #FFFFFF;
  --dark:        #1A2C1E;
  --mid:         #3D5C45;
  --light:       #6B9070;
  --border:      #C4D8C8;
  --accent:      #4A8C64;
  --accent-h:    #5AA878;
  --accent-glow: rgba(74,140,100,.13);
  --loan-col:    #C07840;
  --radius:      12px;
  --shadow:      0 2px 18px rgba(26,44,30,.08), 0 1px 4px rgba(74,140,100,.05);
}

html { scroll-behavior: smooth; }

body {
  font-family: 'DM Sans', sans-serif;
  background:
    linear-gradient(135deg, rgba(147,210,170,.18), transparent 34%),
    linear-gradient(315deg, rgba(180,225,190,.25), transparent 40%),
    var(--bg);
  color: var(--dark);
  min-height: 100vh;
  display: grid;
  grid-template-columns: 220px 1fr;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font: inherit; }
button { border: 0; cursor: pointer; }

/* =============================================
   SIDEBAR
   ============================================= */

.sidebar {
  background: #1A2C1E;
  color: #cde8d4;
  min-height: 100vh;
  height: 100vh;
  position: sticky;
  top: 0;
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  overflow-y: auto;
  border-right: 1px solid rgba(255,255,255,0.05);
  z-index: 100;
}

.brand { display: flex; align-items: center; gap: 12px; }
.brand-icon { font-size: 2rem; line-height: 1; flex-shrink: 0; }
.brand strong, .brand small { display: block; }
.brand strong { font-size: 0.95rem; font-weight: 700; color: #fff; }
.brand small { font-size: 0.72rem; color: #7aaa82; margin-top: 2px; letter-spacing: .02em; }

.nav { display: grid; gap: 4px; }

.nav-button {
  display: flex; align-items: center; gap: 9px;
  text-align: left; padding: 0 12px 0 14px; min-height: 40px;
  border-radius: 8px; background: transparent; color: #8ab292;
  font-size: 0.875rem; font-weight: 500; letter-spacing: .01em;
  border-left: 3px solid transparent; transition: background 160ms ease, color 160ms ease;
}
.nav-button:hover { background: rgba(74,140,100,.12); color: #c5e8cc; }
.nav-button.active {
  background: rgba(74,140,100,.2); color: #fff; font-weight: 600;
  border-left-color: #4A8C64;
}
.nav-button svg { opacity: 0.6; flex-shrink: 0; }
.nav-button.active svg { opacity: 1; }

.badge {
  margin-left: auto; background: var(--loan-col); color: #fff;
  font-size: 0.72rem; font-weight: 700; padding: 1px 7px; border-radius: 50px;
}

.side-actions {
  margin-top: auto; display: grid; gap: 8px; padding-top: 16px;
  border-top: 1px solid rgba(255,255,255,0.07);
}

.side-btn-primary {
  width: 100%; padding: 9px 14px; background: var(--accent); color: white;
  border-radius: 8px; font-size: 0.84rem; font-weight: 700; text-align: center;
}
.side-btn-primary:hover { background: var(--accent-h); }

.side-btn-ghost {
  width: 100%; padding: 8px 14px; background: transparent; color: #8ab292;
  border: 1px solid rgba(255,255,255,0.12); border-radius: 8px;
  font-size: 0.82rem; font-weight: 500;
}
.side-btn-ghost:hover { color: #cde8d4; border-color: rgba(255,255,255,0.25); }

.back-link {
  font-size: 0.72rem; color: rgba(255,255,255,0.25); text-decoration: none;
  text-align: center; margin-top: 4px;
}
.back-link:hover { color: rgba(255,255,255,0.5); }

/* =============================================
   MAIN SHELL
   ============================================= */

.app-shell { min-width: 0; padding: 28px 32px; overflow-y: auto; }

.tab-pane { display: none; }
.tab-pane.active { display: block; }

.section-title { font-size: 1.3rem; font-weight: 700; color: var(--dark); margin-bottom: 4px; }

/* =============================================
   SHELF
   ============================================= */

.shelf-toolbar {
  display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 20px;
  align-items: center;
}

.shelf-search { flex: 1; min-width: 180px; }

.filter-select {
  padding: 8px 12px; border: 1.5px solid var(--border); border-radius: 8px;
  background: var(--surface); color: var(--dark); font-size: 0.875rem;
  outline: none; transition: border-color .2s;
}
.filter-select:focus { border-color: var(--accent); }

.shelf-view-toggle { display: flex; gap: 4px; margin-left: auto; }
.btn-view {
  padding: 7px 10px; border: 1.5px solid var(--border); border-radius: 8px;
  background: var(--surface); color: var(--light);
}
.btn-view.active { border-color: var(--accent); color: var(--accent); background: var(--accent-glow); }

.books-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 16px;
}
.books-grid.view-list {
  grid-template-columns: 1fr;
}

/* Book cards */
.book-card {
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  overflow: hidden; cursor: pointer; transition: transform .2s, box-shadow .2s;
  border: 1px solid var(--border);
}
.book-card:hover { transform: translateY(-3px); box-shadow: 0 8px 28px rgba(26,44,30,.12); }

.book-cover {
  width: 100%; aspect-ratio: 2/3; object-fit: cover; background: #e8f0ea;
  display: flex; align-items: center; justify-content: center; font-size: 2.5rem;
}
.book-cover img { width: 100%; height: 100%; object-fit: cover; }

.book-info { padding: 10px; }
.book-title { font-size: 0.8rem; font-weight: 600; color: var(--dark); margin-bottom: 2px; line-height: 1.3; }
.book-author { font-size: 0.72rem; color: var(--light); }
.book-lent-badge {
  display: inline-block; margin-top: 6px; padding: 2px 7px; border-radius: 50px;
  font-size: 0.68rem; font-weight: 600; background: #FEF3E2; color: var(--loan-col);
}

/* List view */
.book-card.list-card {
  display: flex; align-items: center; gap: 12px; padding: 10px 14px;
}
.book-card.list-card .book-cover { width: 36px; height: 52px; border-radius: 4px; flex-shrink: 0; font-size: 1.4rem; aspect-ratio: unset; }
.book-card.list-card .book-info { padding: 0; flex: 1; }

/* Empty state */
.empty-state { text-align: center; padding: 60px 20px; }
.empty-icon { font-size: 3rem; margin-bottom: 12px; }
.empty-title { font-size: 1.1rem; font-weight: 600; color: var(--dark); margin-bottom: 8px; }
.empty-sub { font-size: 0.88rem; color: var(--light); max-width: 340px; margin: 0 auto 20px; line-height: 1.7; }

/* =============================================
   LOANS
   ============================================= */

.loans-stats {
  display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 20px;
}
.stat-chip {
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 16px; font-size: 0.84rem;
}
.stat-chip strong { color: var(--accent); }

.loan-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 18px; margin-bottom: 10px; display: flex; align-items: center; gap: 14px;
}
.loan-cover {
  width: 40px; height: 58px; border-radius: 6px; object-fit: cover;
  background: #e8f0ea; display: flex; align-items: center; justify-content: center;
  font-size: 1.4rem; flex-shrink: 0;
}
.loan-cover img { width: 100%; height: 100%; object-fit: cover; border-radius: 6px; }
.loan-info { flex: 1; min-width: 0; }
.loan-title { font-weight: 600; font-size: 0.9rem; color: var(--dark); }
.loan-meta { font-size: 0.8rem; color: var(--light); margin-top: 2px; }
.loan-overdue { color: #C05030; }
.btn-return {
  padding: 6px 14px; background: var(--accent-glow); border: 1.5px solid var(--accent);
  border-radius: 50px; color: var(--accent); font-size: 0.8rem; font-weight: 600;
}
.btn-return:hover { background: var(--accent); color: #fff; }

/* =============================================
   EMPRUNTEURS
   ============================================= */

.borrowers-header {
  display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 20px;
}
.borrowers-note { font-size: 0.84rem; color: var(--light); max-width: 480px; line-height: 1.6; }

.borrowers-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px;
}

.borrower-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px; display: flex; align-items: center; justify-content: space-between;
}
.borrower-name { font-weight: 600; font-size: 0.9rem; color: var(--dark); }
.borrower-loans { font-size: 0.78rem; color: var(--light); margin-top: 2px; }
.btn-delete-borrower {
  background: transparent; border: none; color: #C05030; font-size: 1.1rem;
  padding: 4px 8px; border-radius: 6px; opacity: 0.6;
}
.btn-delete-borrower:hover { opacity: 1; background: rgba(192,80,48,.08); }

/* =============================================
   ADD BOOK
   ============================================= */

.add-intro { max-width: 480px; margin: 0 auto; }
.add-methods { display: flex; flex-direction: column; gap: 16px; align-items: center; margin-top: 20px; }

.add-method-card {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  width: 100%; padding: 20px; background: var(--surface); border: 1.5px solid var(--border);
  border-radius: var(--radius); transition: border-color .2s, box-shadow .2s;
}
.add-method-card:hover { border-color: var(--accent); box-shadow: 0 4px 16px var(--accent-glow); }
.method-icon { font-size: 2rem; }
.add-method-card strong { font-size: 0.95rem; color: var(--dark); }
.add-method-card span { font-size: 0.82rem; color: var(--light); }

.method-divider { font-size: 0.8rem; color: var(--light); text-align: center; }

.isbn-row { display: flex; gap: 8px; width: 100%; }
.isbn-row input { flex: 1; }

.btn-text { background: none; border: none; color: var(--accent); font-size: 0.85rem; text-decoration: underline; margin-top: 4px; }

.text-search-wrap { max-width: 560px; }
.text-search-back { background: none; border: none; color: var(--light); font-size: 0.84rem; margin-top: 10px; text-decoration: underline; }
.text-search-results { margin-top: 12px; display: flex; flex-direction: column; gap: 8px; }

.search-result-card {
  display: flex; gap: 12px; align-items: center; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 14px; cursor: pointer;
}
.search-result-card:hover { border-color: var(--accent); }
.search-result-cover { width: 36px; height: 52px; object-fit: cover; border-radius: 4px; background: #e8f0ea; flex-shrink: 0; }
.search-result-info strong { font-size: 0.88rem; color: var(--dark); }
.search-result-info span { font-size: 0.78rem; color: var(--light); display: block; }

/* Scanner */
.scanner-wrap { max-width: 420px; }
.scan-hint { font-size: 0.85rem; color: var(--light); margin-bottom: 12px; }
#reader { border-radius: var(--radius); overflow: hidden; }
.btn-stop {
  margin-top: 12px; padding: 8px 20px; background: #C05030; color: #fff;
  border-radius: 50px; font-weight: 600; font-size: 0.875rem;
}

/* Book form */
.book-form { max-width: 680px; }
.form-header { margin-bottom: 20px; }
.form-header h2 { font-size: 1.1rem; font-weight: 700; color: var(--dark); }
.form-layout { display: grid; grid-template-columns: auto 1fr; gap: 24px; }
.form-cover-preview {
  width: 100px; height: 148px; border-radius: 8px; background: #e8f0ea; border: 1.5px dashed var(--border);
  display: flex; align-items: center; justify-content: center; text-align: center;
  font-size: 0.72rem; color: var(--light); overflow: hidden; flex-shrink: 0;
}
.form-cover-preview img { width: 100%; height: 100%; object-fit: cover; }
.form-fields { display: flex; flex-direction: column; gap: 14px; }
.field-group { display: flex; flex-direction: column; gap: 5px; }
.field-group label { font-size: 0.82rem; font-weight: 600; color: var(--mid); }
.field-hint { font-size: 0.75rem; color: var(--light); }
.field-hint-inline { font-size: 0.75rem; color: var(--light); font-weight: 400; }
.text-input {
  padding: 9px 12px; border: 1.5px solid var(--border); border-radius: 8px;
  background: var(--surface); color: var(--dark); font-size: 0.9rem;
  outline: none; transition: border-color .2s; width: 100%;
}
.text-input:focus { border-color: var(--accent); }
.field-with-voice { display: flex; gap: 6px; }
.btn-voice {
  padding: 8px; background: var(--surface); border: 1.5px solid var(--border);
  border-radius: 8px; color: var(--light); flex-shrink: 0;
}
.btn-voice:hover { border-color: var(--accent); color: var(--accent); }
.btn-voice.recording { border-color: #C05030; color: #C05030; animation: pulse 1s infinite; }
@keyframes pulse { 0%,100% { opacity:1; } 50% { opacity:0.5; } }

.availability-toggle {
  display: flex; align-items: center; gap: 8px; padding: 8px 14px;
  border: 1.5px solid var(--border); border-radius: 8px; background: var(--surface);
  font-size: 0.875rem; font-weight: 500; color: var(--mid);
}
.availability-toggle.available { border-color: var(--accent); color: var(--accent); background: var(--accent-glow); }
.avail-icon { font-size: 1rem; }

.form-actions { display: flex; gap: 10px; margin-top: 20px; }

.btn-primary {
  padding: 10px 22px; background: var(--accent); color: #fff; border-radius: 50px;
  font-weight: 700; font-size: 0.875rem; transition: background .2s;
}
.btn-primary:hover { background: var(--accent-h); }
.btn-secondary {
  padding: 10px 20px; background: var(--surface); border: 1.5px solid var(--border);
  border-radius: 50px; font-weight: 600; font-size: 0.875rem; color: var(--mid);
}
.btn-secondary:hover { border-color: var(--accent); color: var(--accent); }
.btn-sm { padding: 6px 14px; font-size: 0.8rem; }

/* Api loading */
.api-loading { text-align: center; padding: 40px; color: var(--light); }
.spinner {
  width: 32px; height: 32px; border: 3px solid var(--border);
  border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite;
  margin: 0 auto 12px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* =============================================
   MODALS
   ============================================= */

.modal-overlay {
  position: fixed; inset: 0; background: rgba(26,44,30,0.5);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000; padding: 16px;
}
.modal-overlay[hidden] { display: none; }

.modal {
  background: var(--surface); border-radius: 16px; box-shadow: 0 20px 60px rgba(0,0,0,0.2);
  position: relative; max-height: 90vh; overflow-y: auto; width: 100%; max-width: 560px;
}
.modal-sm { max-width: 380px; }

.modal-close {
  position: absolute; top: 14px; right: 14px; width: 30px; height: 30px;
  background: var(--bg); border: none; border-radius: 50%; font-size: 1.1rem;
  color: var(--light); display: flex; align-items: center; justify-content: center;
}
.modal-close:hover { color: var(--dark); }

.modal-body { padding: 28px; }
.modal-body h3 { font-size: 1rem; font-weight: 700; color: var(--dark); margin-bottom: 18px; }

/* Book detail modal */
#book-modal-content { padding: 28px; }
.book-detail-layout { display: flex; gap: 20px; margin-bottom: 20px; }
.book-detail-cover {
  width: 100px; height: 148px; object-fit: cover; border-radius: 8px;
  background: #e8f0ea; display: flex; align-items: center; justify-content: center;
  font-size: 3rem; flex-shrink: 0; overflow: hidden;
}
.book-detail-cover img { width: 100%; height: 100%; object-fit: cover; }
.book-detail-info h2 { font-size: 1.15rem; font-weight: 700; color: var(--dark); margin-bottom: 4px; }
.book-detail-info .author { font-size: 0.9rem; color: var(--mid); margin-bottom: 12px; }
.book-tags { display: flex; flex-wrap: wrap; gap: 6px; }
.book-tag {
  padding: 3px 10px; border-radius: 50px; font-size: 0.75rem; font-weight: 600;
  background: var(--accent-glow); color: var(--accent); border: 1px solid rgba(74,140,100,.25);
}
.book-detail-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 16px; }
.btn-lend { padding: 8px 18px; background: var(--accent); color: #fff; border-radius: 50px; font-weight: 700; font-size: 0.875rem; }
.btn-edit { padding: 8px 18px; background: var(--surface); border: 1.5px solid var(--border); border-radius: 50px; font-weight: 600; font-size: 0.875rem; color: var(--mid); }
.btn-delete-book { padding: 8px 18px; background: rgba(192,80,48,.08); border: 1.5px solid rgba(192,80,48,.25); border-radius: 50px; font-weight: 600; font-size: 0.875rem; color: #C05030; }
.lent-info { background: #FEF3E2; border: 1px solid #F5D9A8; border-radius: 10px; padding: 12px 16px; margin-top: 12px; font-size: 0.875rem; color: var(--loan-col); }

/* Lend modal */
.borrower-field { position: relative; }
.borrower-chip { background: var(--accent); color: #fff; padding: 4px 10px; border-radius: 50px; font-size: 0.82rem; font-weight: 600; display: flex; align-items: center; gap: 6px; width: fit-content; margin-bottom: 6px; }
.autocomplete-list {
  position: absolute; top: 100%; left: 0; right: 0; background: var(--surface);
  border: 1.5px solid var(--border); border-radius: 10px; z-index: 100;
  list-style: none; max-height: 180px; overflow-y: auto; box-shadow: var(--shadow);
}
.autocomplete-list li { padding: 9px 14px; cursor: pointer; font-size: 0.88rem; color: var(--dark); }
.autocomplete-list li:hover { background: var(--accent-glow); }

.input-with-unit { display: flex; gap: 8px; align-items: center; }
.unit { font-size: 0.875rem; color: var(--light); white-space: nowrap; }

/* =============================================
   REMINDER BANNER
   ============================================= */

.reminder-banner {
  background: #FEF3E2; border: 1px solid #F5D9A8; border-radius: var(--radius);
  padding: 12px 18px; margin-bottom: 20px; font-size: 0.875rem; color: var(--loan-col);
}

/* =============================================
   TOAST
   ============================================= */

.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--dark); color: #fff; padding: 10px 22px; border-radius: 50px;
  font-size: 0.875rem; font-weight: 600; z-index: 9999; box-shadow: 0 4px 20px rgba(0,0,0,0.2);
  animation: fadeInUp .25s ease;
}
.toast[hidden] { display: none; }
@keyframes fadeInUp { from { opacity:0; transform:translateX(-50%) translateY(10px); } to { opacity:1; transform:translateX(-50%) translateY(0); } }

/* =============================================
   SPINE SHELF VIEW
   ============================================= */

.spine-shelf-container { display: flex; flex-direction: column; gap: 32px; }

.spine-shelf-section {}

.spine-shelf-theme-label {
  font-size: 0.78rem; font-weight: 700; color: var(--light);
  text-transform: uppercase; letter-spacing: 1.5px; margin-bottom: 10px;
}
.spine-shelf-theme-label span { font-weight: 400; text-transform: none; }

.spine-shelf-row {
  display: flex; gap: 3px; align-items: flex-end;
  padding: 12px 12px 0; background: rgba(26,44,30,.04);
  border-radius: 8px 8px 0 0; min-height: 120px; flex-wrap: wrap;
}

.spine-shelf-plank {
  height: 10px; background: linear-gradient(180deg, #8A7060 0%, #6A5040 100%);
  border-radius: 0 0 4px 4px; box-shadow: 0 4px 8px rgba(0,0,0,0.15);
}

.book-spine {
  height: 100px; border-radius: 3px 2px 2px 3px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; position: relative; overflow: hidden;
  box-shadow: 1px 1px 3px rgba(0,0,0,0.3), inset 1px 0 0 rgba(255,255,255,0.1);
  transition: transform .15s ease, box-shadow .15s ease;
  flex-shrink: 0;
}
.book-spine:hover { transform: translateY(-6px); box-shadow: 2px 4px 8px rgba(0,0,0,0.4); }

.book-spine-title {
  writing-mode: vertical-rl; text-orientation: mixed;
  transform: rotate(180deg); font-size: 0.62rem; font-weight: 600;
  color: rgba(255,255,255,0.85); text-overflow: ellipsis; overflow: hidden;
  white-space: nowrap; max-height: 88px; padding: 4px 2px;
}

/* =============================================
   RESPONSIVE
   ============================================= */

@media (max-width: 680px) {
  body { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .app-shell { padding: 16px; }
  .form-layout { grid-template-columns: 1fr; }
  .books-grid { grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 12px; }
}
