:root {
  --ink: #1a1208;
  --paper: #faf6ef;
  --cream: #f0e9db;
  --warm: #c8a96e;
  --accent: #8b3a2a;
  --muted: #9e8e7a;
  --fiction: #2a5c8b;
  --nonfiction: #3a7a4a;
  --reading: #8b6a2a;
  --read: #3a7a4a;
  --want: #2a5c8b;
}

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

body {
  font-family: 'DM Sans', sans-serif;
  background: var(--paper);
  color: var(--ink);
  min-height: 100vh;
  overflow-x: hidden;
}

/* ── Header ── */

header {
  background: var(--ink);
  color: var(--paper);
  padding: 1.2rem 2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
}

.logo {
  font-family: 'Playfair Display', serif;
  font-size: 1.5rem;
  letter-spacing: -0.01em;
}

.logo span { color: var(--warm); font-style: italic; }

.active-library-name {
  font-family: 'Playfair Display', serif;
  font-size: 1.1rem;
  color: var(--warm);
  font-style: italic;
  margin-left: 0.75rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 220px;
}

.header-actions { display: flex; gap: 0.75rem; align-items: center; }

.btn-add {
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 4px;
  padding: 0.55rem 1.1rem;
  font-family: 'DM Sans', sans-serif;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  transition: opacity 0.2s;
}
.btn-add:hover { opacity: 0.85; }

/* ── Controls ── */

.controls {
  padding: 1.5rem 2rem;
  background: var(--cream);
  border-bottom: 1px solid rgba(0,0,0,0.08);
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  align-items: center;
  overflow: hidden;
}

.search-wrap { flex: 1; min-width: 200px; position: relative; }
.search-wrap input {
  width: 100%;
  padding: 0.65rem 1rem 0.65rem 2.5rem;
  border: 1.5px solid transparent;
  border-radius: 4px;
  background: white;
  font-family: 'DM Sans', sans-serif;
  font-size: 0.95rem;
  transition: border-color 0.2s;
}
.search-wrap input:focus { outline: none; border-color: var(--warm); }
.search-icon {
  position: absolute; left: 0.75rem; top: 50%; transform: translateY(-50%);
  color: var(--muted); font-size: 1rem; pointer-events: none;
}

.filter-group {
  display: flex;
  gap: 0.5rem;
  flex-wrap: nowrap;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  max-width: 100%;
}
.filter-group::-webkit-scrollbar { display: none; }

.filter-btn {
  padding: 0.5rem 1rem;
  border-radius: 20px;
  border: 1.5px solid var(--muted);
  background: white;
  font-family: 'DM Sans', sans-serif;
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--muted);
  cursor: pointer;
  transition: all 0.18s;
  flex-shrink: 0;
  white-space: nowrap;
}
.filter-btn.active, .filter-btn:hover { border-color: var(--accent); color: var(--accent); background: rgba(139,58,42,0.06); }
.filter-btn.active { font-weight: 600; }

/* ── Stats bar ── */

.stats-bar {
  padding: 0.8rem 2rem;
  display: flex;
  gap: 0.5rem;
  font-size: 0.82rem;
  color: var(--muted);
  border-bottom: 1px solid rgba(0,0,0,0.06);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.stats-bar::-webkit-scrollbar { display: none; }

.stat-btn {
  background: none;
  border: 1.5px solid transparent;
  border-radius: 20px;
  padding: 0.3rem 0.75rem;
  font-family: 'DM Sans', sans-serif;
  font-size: 0.82rem;
  color: var(--muted);
  cursor: pointer;
  transition: all 0.18s;
  white-space: nowrap;
  flex-shrink: 0;
}
.stat-btn:hover { border-color: var(--muted); }
.stat-btn.active { border-color: var(--accent); color: var(--accent); background: rgba(139,58,42,0.06); }
.stat-btn strong { color: inherit; font-weight: 600; }

/* ── Book Grid ── */

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 1.5rem;
  padding: 2rem;
}

.book-card {
  background: white;
  border-radius: 4px;
  overflow: hidden;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.book-card:hover { transform: translateY(-3px); box-shadow: 0 6px 16px rgba(0,0,0,0.12); }

.book-cover {
  width: 100%;
  aspect-ratio: 2/3;
  object-fit: cover;
  display: block;
  background: var(--cream);
}

.cover-placeholder {
  width: 100%;
  aspect-ratio: 2/3;
  background: linear-gradient(135deg, var(--cream) 0%, #e0d5c4 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  text-align: center;
}

.cover-placeholder .ph-title {
  font-family: 'Playfair Display', serif;
  font-size: 0.85rem;
  color: var(--ink);
  line-height: 1.3;
  margin-top: 0.5rem;
}
.cover-placeholder .ph-icon { font-size: 2rem; color: var(--warm); }

.book-info { padding: 0.8rem; }
.book-title {
  font-family: 'Playfair Display', serif;
  font-size: 0.92rem;
  line-height: 1.3;
  margin-bottom: 0.25rem;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.book-author { font-size: 0.78rem; color: var(--muted); margin-bottom: 0.5rem; }

.tags { display: flex; gap: 0.3rem; flex-wrap: wrap; }

.tag {
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  padding: 0.2rem 0.5rem;
  border-radius: 3px;
}

.tag-fiction { background: rgba(42,92,139,0.1); color: var(--fiction); }
.tag-nonfiction { background: rgba(58,122,74,0.1); color: var(--nonfiction); }
.tag-read { background: rgba(58,122,74,0.1); color: var(--read); }
.tag-reading { background: rgba(139,106,42,0.1); color: var(--reading); }
.tag-want { background: rgba(42,92,139,0.1); color: var(--want); }

.stars { color: var(--warm); font-size: 0.75rem; letter-spacing: 1px; }

/* ── Empty State ── */

.empty {
  text-align: center;
  padding: 5rem 2rem;
  color: var(--muted);
  grid-column: 1/-1;
}
.empty h2 { font-family: 'Playfair Display', serif; font-size: 1.8rem; color: var(--ink); margin-bottom: 0.5rem; }
.empty p { font-size: 0.95rem; line-height: 1.6; }

/* ── Modal ── */

.modal-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(26,18,8,0.6);
  z-index: 200;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  backdrop-filter: blur(2px);
}
.modal-overlay.open { display: flex; }

.modal {
  background: var(--paper);
  border-radius: 6px;
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
  animation: slideUp 0.25s ease;
}
@keyframes slideUp { from { transform: translateY(20px); opacity: 0; } to { transform: none; opacity: 1; } }

.modal-header {
  padding: 1.5rem 1.5rem 0;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

.modal-header h2 { font-family: 'Playfair Display', serif; font-size: 1.4rem; }
.modal-close {
  background: none; border: none; font-size: 1.4rem; cursor: pointer;
  color: var(--muted); line-height: 1; padding: 0.2rem;
  transition: color 0.2s;
}
.modal-close:hover { color: var(--ink); }

.modal-body { padding: 1.5rem; }

/* ── ISBN Scanner ── */

.scan-section {
  background: var(--cream);
  border-radius: 6px;
  padding: 1.2rem;
  margin-bottom: 1.5rem;
}
.scan-section h3 { font-size: 0.8rem; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); margin-bottom: 0.75rem; }

.scan-row { display: flex; gap: 0.5rem; }
.scan-row input {
  flex: 1;
  padding: 0.65rem 0.9rem;
  border: 1.5px solid transparent;
  border-radius: 4px;
  background: white;
  font-family: 'DM Sans', sans-serif;
  font-size: 1rem;
  transition: border-color 0.2s;
}
.scan-row input:focus { outline: none; border-color: var(--warm); }

.btn-scan, .btn-lookup {
  padding: 0.65rem 1rem;
  border: none;
  border-radius: 4px;
  font-family: 'DM Sans', sans-serif;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: opacity 0.2s;
  white-space: nowrap;
}
.btn-scan { background: var(--ink); color: white; }
.btn-lookup { background: var(--warm); color: white; }
.btn-scan:hover, .btn-lookup:hover { opacity: 0.85; }

#camera-view { display: none; margin-top: 0.75rem; }
#camera-view video {
  width: 100%; border-radius: 4px;
  background: black; aspect-ratio: 16/9; object-fit: cover;
}
.scan-hint { font-size: 0.78rem; color: var(--muted); margin-top: 0.4rem; text-align: center; }
#camera-view { position: relative; }

.focus-ring {
  position: absolute;
  width: 50px;
  height: 50px;
  border: 2px solid var(--warm);
  border-radius: 50%;
  pointer-events: none;
  animation: focusPulse 0.6s ease-out forwards;
  z-index: 10;
}
@keyframes focusPulse {
  0% { transform: scale(1.5); opacity: 0; }
  30% { opacity: 1; }
  100% { transform: scale(0.8); opacity: 0; }
}

.btn-cancel-scan {
  display: block; width: 100%; margin-top: 0.5rem;
  padding: 0.5rem; background: none;
  border: 1.5px solid var(--muted); border-radius: 4px;
  font-family: 'DM Sans', sans-serif; font-size: 0.85rem;
  cursor: pointer; color: var(--muted); transition: all 0.2s;
}
.btn-cancel-scan:hover { border-color: var(--accent); color: var(--accent); }

.lookup-result {
  display: none;
  background: white;
  border-radius: 4px;
  padding: 0.75rem;
  margin-top: 0.75rem;
  gap: 0.75rem;
  align-items: flex-start;
}
.lookup-result.found { display: flex; }
.lookup-result img { width: 50px; border-radius: 2px; }
.lookup-result-info h4 { font-family: 'Playfair Display', serif; font-size: 0.95rem; }
.lookup-result-info p { font-size: 0.82rem; color: var(--muted); }
.btn-use-result {
  margin-top: 0.4rem;
  padding: 0.35rem 0.75rem;
  background: var(--accent); color: white;
  border: none; border-radius: 3px;
  font-size: 0.8rem; cursor: pointer;
  font-family: 'DM Sans', sans-serif;
}

/* ── Form Fields ── */

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
@media (max-width: 480px) { .form-row { grid-template-columns: 1fr; } }

.form-group { margin-bottom: 1rem; }
.form-group label {
  display: block; font-size: 0.78rem; font-weight: 500;
  letter-spacing: 0.07em; text-transform: uppercase;
  color: var(--muted); margin-bottom: 0.35rem;
}
.form-group input, .form-group select, .form-group textarea {
  width: 100%; padding: 0.65rem 0.9rem;
  border: 1.5px solid var(--cream); border-radius: 4px;
  background: white; font-family: 'DM Sans', sans-serif;
  font-size: 0.95rem; transition: border-color 0.2s; color: var(--ink);
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
  outline: none; border-color: var(--warm);
}
.form-group textarea { resize: vertical; min-height: 80px; }

.star-rating { display: flex; gap: 0.3rem; margin-top: 0.25rem; }
.star-btn {
  background: none; border: none; font-size: 1.4rem;
  cursor: pointer; color: #ddd; transition: color 0.15s;
  padding: 0;
}
.star-btn.active { color: var(--warm); }

/* ── Comments ── */

.comments-label {
  display: block; font-size: 0.78rem; font-weight: 500;
  letter-spacing: 0.07em; text-transform: uppercase;
  color: var(--muted); margin-bottom: 0.5rem;
}

.comment-thread {
  max-height: 300px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.comment {
  background: white;
  border: 1px solid var(--cream);
  border-radius: 8px;
  padding: 0.6rem 0.75rem;
}
.comment-own {
  background: rgba(200, 169, 110, 0.08);
  border-color: rgba(200, 169, 110, 0.25);
}

.comment-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.3rem;
  gap: 0.5rem;
}
.comment-author {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--ink);
}
.comment-meta {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.7rem;
  color: var(--muted);
  flex-shrink: 0;
}
.comment-time { white-space: nowrap; }

.comment-badge-shared {
  font-size: 0.62rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.1rem 0.35rem;
  border-radius: 3px;
  background: rgba(42,92,139,0.1);
  color: var(--fiction);
}
.comment-badge-personal {
  font-size: 0.62rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.1rem 0.35rem;
  border-radius: 3px;
  background: rgba(158,142,122,0.15);
  color: var(--muted);
}

.comment-body {
  font-size: 0.88rem;
  line-height: 1.5;
  color: var(--ink);
  white-space: pre-wrap;
  word-break: break-word;
}

.comment-actions {
  display: flex;
  gap: 0.75rem;
  margin-top: 0.3rem;
}
.comment-actions button {
  background: none;
  border: none;
  font-family: 'DM Sans', sans-serif;
  font-size: 0.72rem;
  color: var(--muted);
  cursor: pointer;
  padding: 0;
  transition: color 0.2s;
}
.comment-actions button:hover { color: var(--accent); }

.comment-empty {
  text-align: center;
  padding: 1.5rem 1rem;
  color: var(--muted);
  font-size: 0.85rem;
  font-style: italic;
}

.comment-compose {
  background: white;
  border: 1.5px solid var(--cream);
  border-radius: 8px;
  overflow: hidden;
}
.comment-compose textarea {
  width: 100%;
  padding: 0.65rem 0.75rem;
  border: none;
  font-family: 'DM Sans', sans-serif;
  font-size: 0.9rem;
  color: var(--ink);
  resize: none;
  background: transparent;
}
.comment-compose textarea:focus { outline: none; }
.comment-compose textarea::placeholder { color: var(--muted); }

.comment-compose-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.4rem 0.75rem;
  border-top: 1px solid var(--cream);
  background: rgba(240, 233, 219, 0.3);
}

.visibility-toggle {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.78rem;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
}
.visibility-toggle input[type="checkbox"] {
  width: 14px;
  height: 14px;
  accent-color: var(--fiction);
  cursor: pointer;
}

.btn-comment-post {
  padding: 0.3rem 0.85rem;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 4px;
  font-family: 'DM Sans', sans-serif;
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  transition: opacity 0.2s;
}
.btn-comment-post:hover { opacity: 0.85; }

.modal-move {
  padding: 0 1.5rem;
  margin-bottom: 1rem;
}
.modal-move label {
  display: block; font-size: 0.78rem; font-weight: 500;
  letter-spacing: 0.07em; text-transform: uppercase;
  color: var(--muted); margin-bottom: 0.35rem;
}
.move-row { display: flex; gap: 0.5rem; }
.move-row select {
  flex: 1; padding: 0.55rem 0.9rem;
  border: 1.5px solid var(--cream); border-radius: 4px;
  background: white; font-family: 'DM Sans', sans-serif;
  font-size: 0.9rem; color: var(--ink);
}
.btn-move {
  padding: 0.55rem 1rem; background: var(--fiction);
  color: white; border: none; border-radius: 4px;
  font-family: 'DM Sans', sans-serif; font-size: 0.85rem;
  font-weight: 500; cursor: pointer; transition: opacity 0.2s;
  white-space: nowrap;
}
.btn-move:hover { opacity: 0.85; }

.modal-footer {
  padding: 0 1.5rem 1.5rem;
  display: flex; gap: 0.75rem; justify-content: flex-end;
}
.btn-secondary {
  padding: 0.65rem 1.2rem; background: none;
  border: 1.5px solid var(--cream); border-radius: 4px;
  font-family: 'DM Sans', sans-serif; font-size: 0.95rem;
  cursor: pointer; color: var(--muted); transition: all 0.2s;
}
.btn-secondary:hover { border-color: var(--muted); color: var(--ink); }
.btn-save {
  padding: 0.65rem 1.5rem; background: var(--accent);
  color: white; border: none; border-radius: 4px;
  font-family: 'DM Sans', sans-serif; font-size: 0.95rem;
  font-weight: 500; cursor: pointer; transition: opacity 0.2s;
}
.btn-save:hover { opacity: 0.85; }
.btn-delete {
  padding: 0.65rem 1rem; background: none;
  border: 1.5px solid #e0c8c8; border-radius: 4px;
  font-family: 'DM Sans', sans-serif; font-size: 0.9rem;
  cursor: pointer; color: #a05050; margin-right: auto;
  transition: all 0.2s;
}
.btn-delete:hover { background: #fdf0f0; border-color: #c06060; }

/* ── Toast ── */

.toast {
  position: fixed; bottom: 2rem; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: white;
  padding: 0.75rem 1.5rem; border-radius: 4px;
  font-size: 0.9rem; font-weight: 500; z-index: 999;
  opacity: 0; transition: opacity 0.3s; pointer-events: none;
  white-space: nowrap;
}
.toast.show { opacity: 1; }

/* ── Loading ── */

.loading { text-align: center; padding: 3rem; color: var(--muted); grid-column: 1/-1; }
.spinner {
  width: 2rem; height: 2rem; border: 2px solid var(--cream);
  border-top-color: var(--warm); border-radius: 50%;
  animation: spin 0.8s linear infinite; margin: 0 auto 1rem;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Login Page ── */

.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--cream);
}

.login-container { text-align: center; width: 100%; max-width: 400px; padding: 2rem; }

.login-logo {
  font-family: 'Playfair Display', serif;
  font-size: 2.2rem;
  color: var(--ink);
  margin-bottom: 0.25rem;
}
.login-logo span { color: var(--warm); font-style: italic; }

.login-subtitle { color: var(--muted); font-size: 0.95rem; margin-bottom: 2rem; }

.login-card {
  background: var(--paper);
  border-radius: 8px;
  padding: 2rem;
  box-shadow: 0 2px 12px rgba(0,0,0,0.08);
  text-align: left;
}

.login-tabs { display: flex; gap: 0; margin-bottom: 1.5rem; border-bottom: 2px solid var(--cream); }
.login-tab {
  flex: 1; padding: 0.75rem; background: none; border: none;
  font-family: 'DM Sans', sans-serif; font-size: 0.95rem; font-weight: 500;
  color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent;
  margin-bottom: -2px; transition: all 0.2s;
}
.login-tab.active { color: var(--accent); border-bottom-color: var(--accent); }

.login-error {
  background: #fdf0f0; color: #a05050; padding: 0.75rem; border-radius: 4px;
  font-size: 0.85rem; margin-bottom: 1rem;
}

.btn-login {
  width: 100%; padding: 0.75rem; background: var(--accent); color: white;
  border: none; border-radius: 4px; font-family: 'DM Sans', sans-serif;
  font-size: 1rem; font-weight: 500; cursor: pointer; transition: opacity 0.2s;
}
.btn-login:hover { opacity: 0.85; }

.login-divider {
  text-align: center; margin: 1.5rem 0; position: relative;
  color: var(--muted); font-size: 0.82rem;
}
.login-divider::before {
  content: ''; position: absolute; top: 50%; left: 0; right: 0;
  border-top: 1px solid var(--cream);
}
.login-divider span { background: var(--paper); padding: 0 1rem; position: relative; }

.btn-microsoft {
  display: flex; align-items: center; justify-content: center; gap: 0.75rem;
  width: 100%; padding: 0.75rem; background: white; color: var(--ink);
  border: 1.5px solid var(--cream); border-radius: 4px;
  font-family: 'DM Sans', sans-serif; font-size: 0.95rem; font-weight: 500;
  cursor: pointer; text-decoration: none; transition: all 0.2s;
}
.btn-microsoft:hover { border-color: var(--muted); background: #fafafa; }

/* ── Library Switcher ── */

.library-switcher {
  padding: 0.4rem 0.6rem; border-radius: 4px;
  background: rgba(255,255,255,0.1); color: var(--paper);
  border: 1px solid rgba(255,255,255,0.2);
  font-family: 'DM Sans', sans-serif; font-size: 0.82rem;
  cursor: pointer; max-width: 200px;
}
.library-switcher option { color: var(--ink); background: white; }

/* ── User Menu ── */

.user-menu { display: flex; align-items: center; gap: 0.5rem; }

.user-name { font-size: 0.82rem; color: rgba(255,255,255,0.7); }

.btn-admin, .btn-logout {
  padding: 0.35rem 0.7rem; border-radius: 4px; border: 1px solid rgba(255,255,255,0.2);
  background: none; color: rgba(255,255,255,0.8);
  font-family: 'DM Sans', sans-serif; font-size: 0.75rem;
  cursor: pointer; transition: all 0.2s;
}
.btn-admin:hover, .btn-logout:hover { background: rgba(255,255,255,0.1); color: white; }

/* ── Library Picker Overlay ── */

.picker-overlay {
  position: fixed; inset: 0; background: rgba(26,18,8,0.7);
  z-index: 300; display: flex; align-items: center; justify-content: center;
  backdrop-filter: blur(3px);
}
.picker-card {
  background: var(--paper); border-radius: 8px; padding: 2rem;
  max-width: 400px; width: 100%; text-align: center;
  animation: slideUp 0.25s ease;
}
.picker-card h2 { font-family: 'Playfair Display', serif; margin-bottom: 1.5rem; }

.library-picker-btn {
  display: flex; align-items: center; justify-content: space-between;
  width: 100%; padding: 1rem; margin-bottom: 0.5rem;
  background: white; border: 1.5px solid var(--cream); border-radius: 6px;
  font-family: 'DM Sans', sans-serif; font-size: 1rem;
  cursor: pointer; transition: all 0.2s; text-align: left;
}
.library-picker-btn:hover { border-color: var(--accent); }
.library-picker-btn strong { color: var(--ink); }

.create-library-card {
  max-width: 340px;
  padding: 1.5rem;
}
.create-library-card h2 { font-size: 1.2rem; margin-bottom: 1rem; }
.create-library-input {
  width: 100%; padding: 0.65rem 0.8rem;
  border: 1.5px solid var(--cream); border-radius: 4px;
  background: white; font-family: 'DM Sans', sans-serif;
  font-size: 0.95rem; color: var(--ink);
  margin-bottom: 1rem; box-sizing: border-box;
}
.create-library-input:focus { outline: none; border-color: var(--warm); }
.create-library-actions {
  display: flex; gap: 0.5rem;
}
.create-library-actions .btn-secondary,
.create-library-actions .btn-save { flex: 1; text-align: center; }

.picker-create-row {
  display: flex; gap: 0.5rem; margin-top: 1rem;
  padding-top: 1rem; border-top: 1px solid var(--cream);
}
.picker-create-row input {
  flex: 1; padding: 0.65rem 0.9rem;
  border: 1.5px solid var(--cream); border-radius: 4px;
  background: white; font-family: 'DM Sans', sans-serif;
  font-size: 0.95rem; color: var(--ink);
}
.picker-create-row input:focus { outline: none; border-color: var(--warm); }

.library-type-badge {
  font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.08em;
  font-weight: 600; color: var(--muted); padding: 0.2rem 0.5rem;
  background: var(--cream); border-radius: 3px;
}

/* ── Admin Panel ── */

.admin-panel { max-width: 500px; }

.admin-section-title {
  font-size: 0.78rem; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.08em; color: var(--muted); margin-bottom: 1rem;
}

.create-library-row { display: flex; gap: 0.5rem; margin-bottom: 1rem; }
.create-library-row input { flex: 1; }

.add-member-row { display: flex; gap: 0.5rem; margin-bottom: 1rem; }
.add-member-row input { flex: 1; }

.member-row {
  display: flex; align-items: center; gap: 0.75rem;
  padding: 0.75rem 0; border-bottom: 1px solid var(--cream);
}
.member-info { flex: 1; }
.member-info strong { display: block; font-size: 0.9rem; }
.member-email { font-size: 0.78rem; color: var(--muted); }

.member-role-select {
  padding: 0.3rem 0.5rem; border-radius: 4px; border: 1px solid var(--cream);
  font-family: 'DM Sans', sans-serif; font-size: 0.82rem;
}

.btn-remove-member {
  background: none; border: none; font-size: 1.2rem; color: var(--muted);
  cursor: pointer; padding: 0.2rem 0.4rem; transition: color 0.2s;
}
.btn-remove-member:hover { color: #a05050; }
.btn-remove-member:disabled, .member-role-select:disabled { opacity: 0.4; cursor: not-allowed; }

.danger-zone {
  margin-top: 2rem;
  padding-top: 1.5rem;
  border-top: 1.5px solid #e0c8c8;
}

.danger-zone-desc {
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 1rem;
  line-height: 1.5;
}

.btn-delete-library {
  width: 100%;
  padding: 0.65rem 1rem;
  background: none;
  border: 1.5px solid #e0c8c8;
  border-radius: 4px;
  font-family: 'DM Sans', sans-serif;
  font-size: 0.9rem;
  cursor: pointer;
  color: #a05050;
  transition: all 0.2s;
}
.btn-delete-library:hover { background: #fdf0f0; border-color: #c06060; }

.delete-library-confirm {
  background: #fdf0f0;
  border: 1.5px solid #e0c8c8;
  border-radius: 6px;
  padding: 1rem;
}
.delete-library-confirm p {
  font-size: 0.85rem;
  color: #a05050;
  margin-bottom: 0.5rem;
  font-weight: 500;
}
.delete-library-confirm input {
  width: 100%;
  padding: 0.6rem 0.8rem;
  border: 1.5px solid #e0c8c8;
  border-radius: 4px;
  background: white;
  font-family: 'DM Sans', sans-serif;
  font-size: 0.9rem;
  color: var(--ink);
  margin-bottom: 0.75rem;
  box-sizing: border-box;
}
.delete-library-confirm input:focus { outline: none; border-color: #c06060; }

.delete-library-confirm-actions {
  display: flex;
  gap: 0.5rem;
}
.delete-library-confirm-actions .btn-secondary { flex: 1; text-align: center; }
.btn-delete-library-final {
  flex: 1;
  padding: 0.65rem 1rem;
  background: #a05050;
  color: white;
  border: none;
  border-radius: 4px;
  font-family: 'DM Sans', sans-serif;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: opacity 0.2s;
}
.btn-delete-library-final:hover { opacity: 0.85; }

/* ── Responsive ── */

@media (max-width: 768px) {
  header {
    flex-wrap: wrap;
    padding: 0.6rem 1rem;
    gap: 0.4rem;
    align-items: center;
  }
  .logo { font-size: 1.1rem; }
  .active-library-name {
    font-size: 0.8rem;
    max-width: 120px;
    margin-left: auto;
  }
  .header-actions {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 0.4rem;
  }
  .library-switcher {
    font-size: 0.72rem;
    max-width: 90px;
    padding: 0.3rem 0.4rem;
  }
  .btn-add {
    padding: 0.35rem 0.7rem;
    font-size: 0.78rem;
  }
  .user-menu { margin-left: auto; gap: 0.3rem; }
  .user-name { display: none; }
  .btn-admin, .btn-logout {
    padding: 0.3rem 0.55rem;
    font-size: 0.7rem;
  }

  .controls {
    padding: 0.75rem 1rem;
    flex-direction: column;
    align-items: stretch;
  }
  .search-wrap { min-width: 0; }
  .filter-btn {
    padding: 0.4rem 0.75rem;
    font-size: 0.78rem;
  }

  .stats-bar {
    padding: 0.5rem 0.75rem;
    gap: 0.35rem;
    font-size: 0.75rem;
  }
  .stat-btn {
    padding: 0.25rem 0.6rem;
    font-size: 0.75rem;
  }

  .grid {
    padding: 0.75rem;
    gap: 0.75rem;
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  }
  .book-info { padding: 0.6rem; }
  .book-title { font-size: 0.82rem; }
  .book-author { font-size: 0.72rem; }

  /* Modal — bottom sheet style */
  .modal-overlay { padding: 0; align-items: flex-end; }
  .modal {
    max-height: 95vh;
    max-width: 100%;
    border-radius: 12px 12px 0 0;
  }
  .modal-header { padding: 1rem 1rem 0; }
  .modal-header h2 { font-size: 1.2rem; }
  .modal-body { padding: 1rem; }
  .modal-footer {
    padding: 0 1rem 1rem;
    flex-direction: column;
  }
  .modal-footer .btn-save,
  .modal-footer .btn-secondary,
  .modal-footer .btn-delete {
    width: 100%;
    text-align: center;
    justify-content: center;
  }
  .modal-footer .btn-delete { margin-right: 0; order: 3; }
  .modal-footer .btn-save { order: 1; }
  .modal-footer .btn-secondary { order: 2; }

  /* Form rows stack on mobile */
  .form-row { grid-template-columns: 1fr; }
  .form-group { margin-bottom: 0.75rem; }

  .scan-section { padding: 0.9rem; }
  .scan-row {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 0.5rem;
  }
  .scan-row input { min-width: 0; }
  .scan-row .btn-scan {
    grid-column: 1 / -1;
    width: 100%;
  }

  .star-btn { font-size: 1.6rem; padding: 0.2rem; }

  .comment-thread { max-height: 40vh; }

  .empty { padding: 3rem 1.5rem; }
  .empty h2 { font-size: 1.4rem; }
}

@media (max-width: 380px) {
  .grid { grid-template-columns: repeat(2, 1fr); }
  .active-library-name { max-width: 100px; font-size: 0.82rem; }
  .btn-add span { display: none; }
}
