/* ── Reset & Base ─────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:         #f5f0e8;
  --bg-card:    #ffffff;
  --primary:    #7a3b10;
  --primary-h:  #5e2d0c;
  --accent:     #c0692a;
  --text:       #2c2016;
  --text-muted: #7a6a5a;
  --border:     #e0d5c5;
  --sidebar-w:  240px;
  --radius:     10px;
  --shadow:     0 2px 12px rgba(0,0,0,.08);
  --shadow-lg:  0 8px 32px rgba(0,0,0,.18);
}

html, body {
  height: 100%;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
}

/* ── Sidebar ──────────────────────────────────────────────── */
.sidebar {
  position: fixed;
  top: 0; left: 0; bottom: 0;
  width: var(--sidebar-w);
  background: var(--primary);
  color: #fff;
  display: flex;
  flex-direction: column;
  z-index: 200;
  transition: transform .25s ease;
}

.sidebar-header {
  padding: 28px 20px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid rgba(255,255,255,.15);
  background: none;
  border-left: none;
  border-right: none;
  border-top: none;
  color: inherit;
  width: 100%;
  text-align: left;
  cursor: pointer;
  transition: background .15s;
}

.sidebar-header:hover { background: rgba(255,255,255,.08); }

.sidebar-header h1 {
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: .3px;
}

.logo svg {
  width: 32px; height: 32px;
  flex-shrink: 0;
  stroke: #fff;
}

.stats {
  display: flex;
  padding: 16px 12px;
  border-bottom: 1px solid rgba(255,255,255,.15);
  gap: 4px;
}

.stat {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8px 4px;
  border-radius: 8px;
  background: rgba(255,255,255,.1);
  border: none;
  cursor: pointer;
  color: inherit;
  transition: background .15s;
}

.stat:hover { background: rgba(255,255,255,.22); }

.stat-value {
  font-size: 1.4rem;
  font-weight: 700;
  line-height: 1;
}

.stat-label {
  font-size: .65rem;
  opacity: .75;
  margin-top: 3px;
  text-transform: uppercase;
  letter-spacing: .5px;
}

.nav-links {
  list-style: none;
  padding: 12px 0;
  flex: 1;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 20px;
  color: rgba(255,255,255,.8);
  text-decoration: none;
  font-size: .9rem;
  font-weight: 500;
  transition: background .15s, color .15s;
  border-radius: 0;
}

.nav-link svg {
  width: 18px; height: 18px;
  flex-shrink: 0;
}

.nav-link:hover {
  background: rgba(255,255,255,.12);
  color: #fff;
}

.nav-link.active {
  background: rgba(255,255,255,.2);
  color: #fff;
}

.user-section {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  border-top: 1px solid rgba(255,255,255,.15);
  margin-top: auto;
}

.user-avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}

.user-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.user-name {
  font-size: .78rem;
  font-weight: 600;
  color: rgba(255,255,255,.9);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.signout-btn {
  background: none;
  border: none;
  color: rgba(255,255,255,.55);
  font-size: .72rem;
  cursor: pointer;
  padding: 0;
  text-align: left;
  transition: color .15s;
}

.signout-btn:hover { color: rgba(255,255,255,.9); }

/* ── Auth hidden ──────────────────────────────────────────── */
.auth-hidden { display: none !important; }

/* ── Auth loading overlay ─────────────────────────────────── */
.auth-loading {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1001;
}

.auth-loading.hidden { display: none !important; }

.auth-loading-spinner {
  width: 40px; height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}

/* ── Login screen ─────────────────────────────────────────── */
.login-screen {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 24px;
}

.login-card {
  background: var(--bg-card);
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
  padding: 48px 40px;
  max-width: 400px;
  width: 100%;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.login-icon {
  width: 64px; height: 64px;
  background: var(--primary);
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 4px;
}

.login-icon svg {
  width: 36px; height: 36px;
  stroke: #fff;
}

.login-card h1 {
  font-size: 1.6rem;
  font-weight: 700;
}

.login-card p {
  color: var(--text-muted);
  font-size: .95rem;
  line-height: 1.5;
  margin-bottom: 8px;
}

.login-invite-error {
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: #b91c1c;
  border-radius: 8px;
  padding: 10px 14px;
  font-size: .88rem;
  line-height: 1.5;
  margin-bottom: 8px;
  text-align: left;
}

.btn-google {
  display: flex;
  align-items: center;
  gap: 12px;
  background: #fff;
  border: 1.5px solid #dadce0;
  border-radius: var(--radius);
  padding: 11px 20px;
  font-size: .95rem;
  font-weight: 600;
  color: #3c4043;
  cursor: pointer;
  transition: background .15s, box-shadow .15s;
  width: 100%;
  justify-content: center;
}

.btn-google svg {
  width: 20px; height: 20px;
  flex-shrink: 0;
}

.btn-google:hover {
  background: #f8f9fa;
  box-shadow: 0 2px 8px rgba(0,0,0,.1);
}

/* ── Mobile header ────────────────────────────────────────── */
.mobile-header {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 56px;
  background: var(--primary);
  color: #fff;
  align-items: center;
  padding: 0 16px;
  z-index: 150;
  gap: 12px;
}

.mobile-header h1 {
  flex: 1;
  font-size: 1.1rem;
  font-weight: 700;
}

.mobile-brand-btn {
  cursor: pointer;
  border-radius: 6px;
  padding: 2px 6px;
  margin: -2px -6px;
  transition: background .15s;
}

.mobile-brand-btn:hover { background: rgba(255,255,255,.15); }

.hamburger {
  background: none;
  border: none;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding: 4px;
}

.hamburger span {
  display: block;
  width: 22px; height: 2px;
  background: #fff;
  border-radius: 2px;
  transition: .2s;
}

.mobile-add-btn {
  background: rgba(255,255,255,.2);
  border: none;
  color: #fff;
  font-size: 1.4rem;
  width: 34px; height: 34px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.4);
  z-index: 190;
}

/* ── Main content ─────────────────────────────────────────── */
.main-content {
  margin-left: var(--sidebar-w);
  min-height: 100vh;
  padding: 32px;
}

/* ── Views ────────────────────────────────────────────────── */
.view { display: none; }
.view.active { display: block; }

.view-header {
  display: flex;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 16px;
  margin-bottom: 28px;
}

.view-header h2 {
  font-size: 1.6rem;
  font-weight: 700;
  flex-shrink: 0;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-left: auto;
  align-items: center;
}

.search-box {
  position: relative;
  display: flex;
  align-items: center;
}

.search-box svg {
  position: absolute;
  left: 10px;
  width: 16px; height: 16px;
  stroke: var(--text-muted);
  pointer-events: none;
}

.search-box input {
  padding: 8px 12px 8px 34px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-card);
  font-size: .88rem;
  color: var(--text);
  width: 210px;
  transition: border-color .15s;
}

.search-box input:focus {
  outline: none;
  border-color: var(--accent);
}

.select-control {
  padding: 8px 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-card);
  font-size: .88rem;
  color: var(--text);
  cursor: pointer;
  transition: border-color .15s;
}

.select-control:focus {
  outline: none;
  border-color: var(--accent);
}

/* ── Manual entry form ────────────────────────────────────── */
.btn-link {
  background: none;
  border: none;
  color: var(--primary);
  font-size: .88rem;
  font-weight: 600;
  cursor: pointer;
  padding: 0;
  margin-left: 8px;
  text-decoration: underline;
}

.manual-form {
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
  margin-top: 12px;
}

.manual-form h3 {
  font-size: 1.05rem;
  font-weight: 700;
  margin-bottom: 18px;
}

.manual-fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 16px;
}

.manual-fields label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: .8rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .4px;
}

.manual-fields label:first-child {
  grid-column: 1 / -1;
}

.manual-fields input {
  padding: 9px 12px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  font-size: .9rem;
  color: var(--text);
  transition: border-color .15s;
  font-weight: 400;
}

.manual-fields input:focus {
  outline: none;
  border-color: var(--accent);
}

.required { color: var(--accent); }

.manual-actions {
  display: flex;
  gap: 10px;
  margin-top: 16px;
}

@media (max-width: 768px) {
  .manual-fields { grid-template-columns: 1fr; }
  .manual-fields label:first-child { grid-column: 1; }
}

/* ── Book Grid ────────────────────────────────────────────── */
.book-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(148px, 1fr));
  gap: 20px;
}

.book-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  cursor: pointer;
  transition: transform .18s, box-shadow .18s;
  display: flex;
  flex-direction: column;
}

.book-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 8px 24px rgba(0,0,0,.13);
}

.book-cover-wrap {
  aspect-ratio: 2/3;
  background: #e8dfd0;
  overflow: hidden;
  position: relative;
}

.book-cover-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.book-cover-placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px;
  text-align: center;
  background: linear-gradient(135deg, #d4c5b0, #c0aa90);
}

.book-cover-placeholder svg {
  width: 36px; height: 36px;
  stroke: rgba(60,30,10,.4);
}

.book-cover-placeholder span {
  font-size: .72rem;
  font-weight: 600;
  color: rgba(60,30,10,.5);
  word-break: break-word;
  line-height: 1.3;
}

.status-badge {
  position: absolute;
  top: 6px; right: 6px;
  font-size: .6rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .4px;
  padding: 2px 6px;
  border-radius: 20px;
  line-height: 1.6;
}

.status-badge.want    { background: #fff3cd; color: #856404; }
.status-badge.reading { background: #cff4fc; color: #055160; }
.status-badge.read    { background: #d1e7dd; color: #0a3622; }

.book-card-info {
  padding: 10px 11px 12px;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.book-card-title {
  font-size: .82rem;
  font-weight: 600;
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.book-card-author {
  font-size: .73rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Empty state ──────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 80px 20px;
  color: var(--text-muted);
}

.empty-state svg {
  width: 64px; height: 64px;
  stroke: var(--border);
  margin-bottom: 16px;
}

.empty-state h3 {
  font-size: 1.2rem;
  margin-bottom: 8px;
  color: var(--text);
}

.empty-state p {
  margin-bottom: 24px;
}

/* ── Add view tabs ────────────────────────────────────────── */
.add-tabs {
  display: flex;
  gap: 4px;
  background: var(--bg);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 4px;
  width: fit-content;
  margin-bottom: 24px;
}

.add-tab {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 8px 16px;
  border: none;
  border-radius: 7px;
  background: none;
  font-size: .88rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  transition: background .15s, color .15s;
}

.add-tab svg {
  width: 15px; height: 15px;
  flex-shrink: 0;
}

.add-tab:hover { background: var(--border); color: var(--text); }

.add-tab.active {
  background: var(--bg-card);
  color: var(--primary);
  box-shadow: var(--shadow);
}

.add-tab-panel { display: none; }
.add-tab-panel.active { display: block; }

/* ── Add book form ────────────────────────────────────────── */
.add-form-container {
  max-width: 700px;
}

.form-hint {
  color: var(--text-muted);
  margin-bottom: 20px;
  font-size: .92rem;
}

.isbn-form {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
}

.isbn-form input {
  flex: 1;
  padding: 11px 16px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-card);
  font-size: 1rem;
  color: var(--text);
  transition: border-color .15s;
  letter-spacing: 1px;
}

.isbn-form input:focus {
  outline: none;
  border-color: var(--accent);
}

.error-msg {
  color: #c0392b;
  font-size: .88rem;
  margin-bottom: 16px;
  padding: 10px 14px;
  background: #fdecea;
  border-radius: 8px;
  border-left: 3px solid #e74c3c;
}

/* ── Book preview ─────────────────────────────────────────── */
.book-preview {
  display: flex;
  gap: 28px;
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
  margin-top: 8px;
  align-items: flex-start;
}

.book-preview img {
  width: 120px;
  min-width: 120px;
  aspect-ratio: 2/3;
  object-fit: cover;
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0,0,0,.15);
  background: #e0d5c5;
}

.preview-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.preview-info h3 {
  font-size: 1.2rem;
  font-weight: 700;
  line-height: 1.3;
}

.meta-author {
  color: var(--accent);
  font-weight: 600;
  font-size: .95rem;
}

.meta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.meta-chip {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 2px 10px;
  font-size: .78rem;
  color: var(--text-muted);
}

.meta-chip:empty { display: none; }

.subjects {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.subject-tag {
  background: #f0e6d3;
  color: var(--primary);
  border-radius: 20px;
  padding: 2px 10px;
  font-size: .74rem;
  font-weight: 500;
}

.status-select-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 4px;
}

.status-select-row label {
  font-size: .88rem;
  color: var(--text-muted);
  white-space: nowrap;
}

/* ── Book search results ──────────────────────────────────── */
.search-results {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 16px;
  max-width: 700px;
}

.search-no-results {
  color: var(--text-muted);
  font-size: .9rem;
  margin-top: 16px;
}

.search-result-item {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 12px 14px;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: background .15s;
}

.search-result-item:hover { background: #fdfaf6; }

.search-result-cover {
  width: 42px;
  min-width: 42px;
  aspect-ratio: 2/3;
  border-radius: 4px;
  overflow: hidden;
  background: #e8dfd0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.search-result-cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.search-result-no-cover svg {
  width: 20px; height: 20px;
  stroke: #b0a090;
}

.search-result-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.search-result-title {
  font-size: .9rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.search-result-author {
  font-size: .8rem;
  color: var(--accent);
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.search-result-meta {
  font-size: .75rem;
  color: var(--text-muted);
}

.search-result-btn {
  flex-shrink: 0;
  padding: 6px 14px;
  font-size: .82rem;
}

.preview-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 4px;
}

/* ── Scanner ──────────────────────────────────────────────── */
.scan-container {
  max-width: 520px;
}

#reader-wrapper {
  margin: 0 0 16px;
  border-radius: var(--radius);
  overflow: hidden;
  background: #000;
  min-height: 0;
}

#reader { width: 100%; }

.scan-result {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow);
  margin-top: 16px;
}

.scan-result p {
  margin-bottom: 14px;
  font-size: .95rem;
}

.scan-actions {
  display: flex;
  gap: 10px;
}

/* ── Buttons ──────────────────────────────────────────────── */
.btn {
  padding: 9px 20px;
  border: none;
  border-radius: var(--radius);
  font-size: .9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, transform .1s;
  white-space: nowrap;
}

.btn:active { transform: scale(.97); }

.btn-primary {
  background: var(--primary);
  color: #fff;
}

.btn-primary:hover { background: var(--primary-h); }

.btn-secondary {
  background: var(--bg);
  color: var(--text);
  border: 1.5px solid var(--border);
}

.btn-secondary:hover { background: var(--border); }

.btn-danger {
  background: #fdecea;
  color: #c0392b;
  border: 1.5px solid #f5c6c6;
  margin-top: auto;
}

.btn-danger:hover { background: #f5c6c6; }

/* ── Modal ────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.55);
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  backdrop-filter: blur(2px);
}

.modal-overlay.hidden { display: none; }

.modal {
  background: var(--bg-card);
  border-radius: 14px;
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 700px;
  max-height: 90vh;
  overflow-y: auto;
  position: relative;
}

.modal-close {
  position: absolute;
  top: 14px; right: 14px;
  background: var(--bg);
  border: none;
  width: 32px; height: 32px;
  border-radius: 50%;
  font-size: 1.2rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  transition: background .15s;
  z-index: 1;
}

.modal-close:hover { background: var(--border); color: var(--text); }

.modal-body {
  display: flex;
  gap: 28px;
  padding: 28px;
}

.modal-cover-col {
  display: flex;
  flex-direction: column;
  gap: 14px;
  flex-shrink: 0;
  width: 150px;
}

#modal-cover {
  width: 150px;
  aspect-ratio: 2/3;
  object-fit: cover;
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0,0,0,.18);
  background: #e0d5c5;
}

.modal-status-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.modal-status-row label {
  font-size: .8rem;
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .4px;
}

.modal-info-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
}

.modal-info-col h2 {
  font-size: 1.35rem;
  font-weight: 700;
  line-height: 1.3;
}

.modal-meta {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px 16px;
}

.modal-meta-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.modal-meta-label {
  font-size: .72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .4px;
  color: var(--text-muted);
}

.modal-meta-value {
  font-size: .9rem;
  color: var(--text);
}

.modal-description {
  font-size: .88rem;
  color: var(--text-muted);
  line-height: 1.65;
  border-top: 1px solid var(--border);
  padding-top: 12px;
}

/* ── Modal notes ──────────────────────────────────────────── */
.modal-notes-section {
  border-top: 1px solid var(--border);
  padding-top: 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.modal-notes-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-notes-header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.notes-private-toggle {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: .78rem;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
}

.notes-private-toggle input[type="checkbox"] {
  width: 13px; height: 13px;
  accent-color: var(--primary);
  cursor: pointer;
}

.modal-notes-input {
  width: 100%;
  padding: 10px 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  font-size: .88rem;
  color: var(--text);
  font-family: inherit;
  line-height: 1.6;
  resize: vertical;
  transition: border-color .15s;
  min-height: 90px;
}

.modal-notes-input:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--bg-card);
}

.modal-notes-input:disabled {
  opacity: .6;
  cursor: default;
  resize: none;
}

.notes-saved {
  font-size: .75rem;
  font-weight: 600;
  color: #2e7d32;
  transition: opacity .3s;
}

/* ── Toast ────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%);
  background: #1a1a1a;
  color: #fff;
  padding: 11px 22px;
  border-radius: 30px;
  font-size: .88rem;
  font-weight: 500;
  z-index: 1000;
  box-shadow: 0 4px 16px rgba(0,0,0,.25);
  transition: opacity .3s;
}

.toast.hidden { display: none; }

/* ── Utilities ────────────────────────────────────────────── */
.hidden { display: none !important; }

/* ── Loading spinner ──────────────────────────────────────── */
.spinner {
  display: inline-block;
  width: 18px; height: 18px;
  border: 2px solid rgba(255,255,255,.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .7s linear infinite;
  vertical-align: middle;
  margin-right: 6px;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── Rating badge on card ─────────────────────────────────── */
.card-rating {
  position: absolute;
  bottom: 6px; right: 6px;
  background: rgba(0,0,0,.65);
  color: #fff;
  font-size: .68rem;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 20px;
  letter-spacing: .3px;
}

/* ── Rating slider widget ─────────────────────────────────── */
.rating-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 4px 0;
}

.rating-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.rating-label {
  font-size: .8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .4px;
  color: var(--text-muted);
}

.rating-value {
  font-size: .85rem;
  font-weight: 700;
  color: var(--primary);
}

.rating-slider-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
}

.rating-slider {
  --fill: 0%;
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 6px;
  border-radius: 3px;
  background: linear-gradient(to right, var(--primary) var(--fill), var(--border) var(--fill));
  outline: none;
  cursor: pointer;
  transition: background .1s;
}

.rating-slider.unfilled {
  background: var(--border);
}

.rating-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: var(--primary);
  cursor: pointer;
  box-shadow: 0 1px 4px rgba(0,0,0,.2);
  transition: transform .1s;
}

.rating-slider::-webkit-slider-thumb:hover { transform: scale(1.2); }
.rating-slider::-moz-range-thumb {
  width: 18px; height: 18px;
  border-radius: 50%;
  background: var(--primary);
  border: none;
  cursor: pointer;
}

.rating-slider:disabled {
  cursor: default;
  opacity: .6;
}

.rating-slider:disabled::-webkit-slider-thumb { cursor: default; }

.rating-clear-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: .75rem;
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 4px;
  line-height: 1;
  transition: color .15s, background .15s;
}

.rating-clear-btn:hover {
  color: #c0392b;
  background: #fdecea;
}

/* ── Viewing banner ───────────────────────────────────────── */
.viewing-banner {
  display: flex;
  align-items: center;
  gap: 12px;
  background: #fff8e8;
  border: 1.5px solid #f0d78a;
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-bottom: 24px;
  font-size: .9rem;
  color: var(--text);
}

.viewing-avatar-img {
  width: 32px; height: 32px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}

.viewing-banner .btn-link {
  margin-left: auto;
  font-size: .85rem;
}

/* ── Private badge on book cards ──────────────────────────── */
.private-badge {
  position: absolute;
  top: 6px; left: 6px;
  background: rgba(0,0,0,.55);
  border-radius: 6px;
  width: 24px; height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.private-badge svg {
  width: 13px; height: 13px;
  stroke: #fff;
}

/* ── Private toggle ───────────────────────────────────────── */
.private-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: .85rem;
  color: var(--text-muted);
  cursor: pointer;
  margin: 4px 0;
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
}

.private-toggle input[type="checkbox"] {
  width: 15px; height: 15px;
  accent-color: var(--primary);
  cursor: pointer;
  flex-shrink: 0;
}

/* ── Feed ─────────────────────────────────────────────────── */
.feed-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-width: 640px;
}

.feed-item {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
  transition: background .15s;
}

.feed-item:hover { background: #fdfaf6; }

.feed-avatar-link { flex-shrink: 0; text-decoration: none; }

.feed-avatar {
  width: 40px; height: 40px;
  border-radius: 50%;
  object-fit: cover;
  display: block;
}

.feed-avatar-initials {
  width: 40px; height: 40px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .95rem;
  font-weight: 700;
}

.feed-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.feed-text {
  font-size: .88rem;
  line-height: 1.45;
  color: var(--text);
}

.feed-name {
  font-weight: 700;
  color: var(--primary);
  text-decoration: none;
}

.feed-name:hover { text-decoration: underline; }

.feed-text em {
  font-style: normal;
  font-weight: 600;
}

.feed-time {
  font-size: .75rem;
  color: var(--text-muted);
}

.feed-cover {
  width: 36px;
  aspect-ratio: 2/3;
  object-fit: cover;
  border-radius: 4px;
  flex-shrink: 0;
  box-shadow: 0 2px 6px rgba(0,0,0,.15);
}

/* ── Nav badge ────────────────────────────────────────────── */
.nav-badge {
  margin-left: auto;
  background: #e74c3c;
  color: #fff;
  font-size: .65rem;
  font-weight: 700;
  min-width: 18px;
  height: 18px;
  border-radius: 9px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 5px;
  line-height: 1;
}

/* ── Small button variant ─────────────────────────────────── */
.btn-sm {
  padding: 5px 12px;
  font-size: .8rem;
  border-radius: 7px;
}

.btn-danger-sm {
  background: #fdecea;
  color: #c0392b;
  border: 1.5px solid #f5c6c6;
  padding: 5px 12px;
  font-size: .8rem;
  border-radius: 7px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s;
  white-space: nowrap;
}

.btn-danger-sm:hover { background: #f5c6c6; }

/* ── Find friend form ─────────────────────────────────────── */
.find-friend-form {
  display: flex;
  gap: 10px;
  max-width: 480px;
}

.find-friend-form input {
  flex: 1;
  padding: 9px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-card);
  font-size: .92rem;
  color: var(--text);
  transition: border-color .15s;
}

.find-friend-form input:focus {
  outline: none;
  border-color: var(--accent);
}

.friend-status-chip {
  font-size: .8rem;
  font-weight: 600;
  color: var(--text-muted);
  padding: 5px 12px;
  border-radius: 7px;
  border: 1.5px solid var(--border);
  white-space: nowrap;
}
.invite-joined  { color: #16a34a; border-color: #bbf7d0; }
.invite-pending { color: var(--text-muted); }

.friends-section-hint {
  font-size: .88rem;
  color: var(--text-muted);
  margin-bottom: 10px;
}

/* ── Friends view ─────────────────────────────────────────── */
.friends-section {
  max-width: 640px;
  margin-bottom: 32px;
}

.friends-section-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 12px;
  padding-bottom: 10px;
  border-bottom: 1.5px solid var(--border);
}

.friends-section-title svg {
  width: 18px; height: 18px;
  stroke: var(--primary);
  flex-shrink: 0;
}

.friends-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.friend-item {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 12px 14px;
  box-shadow: var(--shadow);
}

.friend-avatar-link {
  flex-shrink: 0;
  text-decoration: none;
  display: block;
}

.friend-avatar {
  width: 40px; height: 40px;
  border-radius: 50%;
  object-fit: cover;
  display: block;
}

.friend-initials {
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .95rem;
  font-weight: 700;
}

.friend-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.friend-name {
  font-size: .9rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.friend-subtext {
  font-size: .75rem;
  color: var(--text-muted);
}

.friend-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.friends-empty {
  color: var(--text-muted);
  font-size: .9rem;
  padding: 12px 0;
}

/* ── Friend ratings in modal ──────────────────────────────── */
.friend-ratings-section {
  border-top: 1px solid var(--border);
  padding-top: 14px;
  margin-top: 4px;
}

.friend-ratings-title {
  font-size: .8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .4px;
  color: var(--text-muted);
  margin-bottom: 10px;
}

.friend-rating-item {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-bottom: 7px;
}

.friend-rating-avatar {
  width: 26px; height: 26px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  display: block;
}

.friend-rating-name {
  flex: 1;
  font-size: .85rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.friend-rating-value {
  font-size: .85rem;
  font-weight: 700;
  color: var(--primary);
  flex-shrink: 0;
}

.friend-ratings-loading {
  font-size: .82rem;
  color: var(--text-muted);
}

/* ── Responsive ───────────────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .sidebar-overlay.open {
    display: block;
  }

  .mobile-header {
    display: flex;
  }

  .main-content {
    margin-left: 0;
    padding: 80px 16px 24px;
  }

  .book-preview {
    flex-direction: column;
  }

  .book-preview img {
    width: 100px;
    min-width: 100px;
  }

  .modal-body {
    flex-direction: column;
    padding: 20px;
  }

  .modal-cover-col {
    width: 100%;
    flex-direction: row;
    align-items: flex-start;
    gap: 16px;
  }

  #modal-cover {
    width: 100px;
  }

  .modal-cover-col .btn-danger {
    margin-top: 0;
    align-self: flex-end;
  }

  .modal-meta {
    grid-template-columns: 1fr;
  }

  .controls {
    width: 100%;
  }

  .search-box input {
    width: 100%;
  }

  .isbn-form {
    flex-direction: column;
  }
}
