:root {
  /* Light theme (default) */
  --bg-body: #f8f9fa;
  --bg-card: #ffffff;
  --bg-nav: #ffffff;
  --bg-input: #ffffff;
  --text-primary: #212529;
  --text-secondary: #6c757d;
  --text-muted: #adb5bd;
  --border-color: #dee2e6;
  --accent: #0d6efd;
  --accent-hover: #0b5ed7;
  --accent-soft: #e7f1ff;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.1);
  --radius-sm: 6px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-full: 50%;
  --topbar-height: 56px;
  --bottomnav-height: 64px;
  --transition-fast: 0.15s ease;
  --transition-normal: 0.2s ease;
}

[data-theme="dark"] {
  --bg-body: #1a1d21;
  --bg-card: #2b3035;
  --bg-nav: #212529;
  --bg-input: #2b3035;
  --text-primary: #dee2e6;
  --text-secondary: #adb5bd;
  --text-muted: #6c757d;
  --border-color: #343a40;
  --accent: #3d8bfd;
  --accent-hover: #5a9cfd;
  --accent-soft: #1e3a5f;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.2);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.3);
}

body {
  background: var(--bg-body);
  color: var(--text-primary);
  padding-top: var(--topbar-height);
  padding-bottom: calc(var(--bottomnav-height) + 16px);
  font-family: system-ui, -apple-system, sans-serif;
}

.topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--topbar-height);
  background: var(--bg-nav);
  border-bottom: 1px solid var(--border-color);
  z-index: 1030;
  display: flex;
  align-items: center;
  padding: 0 16px;
  box-shadow: var(--shadow-sm);
}

.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--bottomnav-height);
  background: var(--bg-nav);
  border-top: 1px solid var(--border-color);
  z-index: 1030;
  display: flex;
  justify-content: space-around;
  align-items: center;
  padding: 4px 0;
  box-shadow: 0 -1px 3px rgba(0,0,0,0.08);
}

.bottom-nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  text-decoration: none;
  color: var(--text-secondary);
  font-size: 11px;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  transition: var(--transition-fast);
}

.bottom-nav-item:hover, .bottom-nav-item:focus {
  color: var(--accent);
  text-decoration: none;
}

.bottom-nav-item.active {
  color: var(--accent);
  font-weight: 600;
}

.bottom-nav-item .nav-icon {
  font-size: 22px;
}

.nav-scan-btn {
  width: 48px;
  height: 48px;
  background: var(--accent) !important;
  color: white !important;
  border-radius: 50%;
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  box-shadow: var(--shadow-md);
  margin-top: -12px;
  cursor: pointer;
  border: none;
  padding: 0;
}
.nav-scan-btn:hover,
.nav-scan-btn:focus {
  background: var(--accent-hover) !important;
  color: white !important;
}

.book-card {
  background: var(--bg-card);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  transition: var(--transition-normal);
  cursor: pointer;
  position: relative;
}

.book-card:active {
  transform: scale(0.98);
}

.book-cover {
  width: 100%;
  aspect-ratio: 2/3;
  object-fit: cover;
  background: #e9ecef;
}

.book-cover-placeholder {
  width: 100%;
  aspect-ratio: 2/3;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #e9ecef;
  color: var(--text-muted);
  font-size: 48px;
}

.book-card-body {
  padding: 10px 12px;
}

.book-card-title {
  font-size: 14px;
  font-weight: 600;
  line-height: 1.3;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  margin-bottom: 0;
}

.book-card-author {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 0;
}

.book-card-badge {
  position: absolute;
  top: 8px;
  right: 8px;
  font-size: 10px;
  font-weight: bold;
  padding: 2px 6px;
  border-radius: var(--radius-sm);
}

.book-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
  padding: 12px 0;
}

@media (min-width: 576px) {
  .book-grid {
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 16px;
  }
}

@media (min-width: 768px) {
  .book-grid {
    grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  }
}

.search-bar {
  position: sticky;
  top: var(--topbar-height);
  background: var(--bg-body);
  z-index: 10;
  padding: 12px 0;
}

.search-input {
  border-radius: 24px;
  padding-left: 40px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  height: 44px;
}

.filter-row {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 8px 0;
  -webkit-overflow-scrolling: touch;
}

.filter-row::-webkit-scrollbar {
  display: none;
}

.filter-pill {
  border-radius: 20px;
  height: 34px;
  font-size: 13px;
  border: 1px solid var(--border-color);
  background: var(--bg-card);
  padding: 0 14px;
  white-space: nowrap;
}

.filter-pill:focus, .filter-pill.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
  outline: none;
  box-shadow: none;
}

.fab {
  position: fixed;
  bottom: calc(var(--bottomnav-height) + 20px);
  right: 20px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  border: none;
  box-shadow: var(--shadow-md);
  font-size: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1020;
  transition: var(--transition-normal);
}

.fab:active {
  transform: scale(0.9);
}

.star-rating {
  display: inline-flex;
  gap: 2px;
}
.star-rating .bi {
  color: #ffc107;
  font-size: 16px;
  cursor: pointer;
}

.photo-gallery {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 8px 0;
}
.photo-gallery::-webkit-scrollbar {
  display: none;
}

.photo-thumb {
  width: 72px;
  height: 72px;
  border-radius: var(--radius-sm);
  object-fit: cover;
  border: 2px solid transparent;
  cursor: pointer;
  position: relative;
  flex-shrink: 0;
}

.photo-thumb.default {
  border-color: var(--accent);
}

.photo-thumb-wrapper {
  position: relative;
  display: inline-block;
}

.photo-thumb-remove {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 20px;
  height: 20px;
  background: #dc3545;
  color: white;
  border-radius: 50%;
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 5;
}

.save-toast {
  border-radius: 20px;
  padding: 8px 14px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.12);
  opacity: 0;
  transform: translateY(-8px);
  transition: opacity 0.2s, transform 0.2s;
}

.save-toast.show {
  opacity: 1;
  transform: translateY(0);
}

.shelf-card {
  background: var(--bg-card);
  border-radius: var(--radius-md);
  padding: 16px;
  border: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.shelf-card-count {
  font-size: 28px;
  font-weight: 700;
  color: var(--accent);
}

.loan-card {
  background: var(--bg-card);
  border-radius: var(--radius-md);
  padding: 16px;
  border: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  gap: 16px;
}

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}

.empty-state-icon {
  font-size: 64px;
  margin-bottom: 16px;
}

.empty-state-text {
  font-size: 18px;
  margin-bottom: 8px;
  font-weight: 600;
  color: var(--text-primary);
}

.empty-state-sub {
  font-size: 14px;
}

/* Badges */
.badge-lent {
  background: #fff3cd;
  color: #856404;
}
[data-theme="dark"] .badge-lent {
  background: #664d03;
  color: #ffc107;
}

.badge-read {
  background: #d1e7dd;
  color: #0f5132;
}
.badge-reading {
  background: #cff4fc;
  color: #055160;
}
.badge-unread {
  background: #e9ecef;
  color: #495057;
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 0;
  margin-bottom: 8px;
}

.page-title {
  font-size: 24px;
  font-weight: 700;
}

.settings-section {
  border-bottom: 1px solid var(--border-color);
  padding: 16px 0;
}
.settings-section:last-child {
  border-bottom: none;
}

.cover-preview-container {
  width: 100%;
  max-width: 200px;
  margin: 0 auto;
  aspect-ratio: 2/3;
  border-radius: var(--radius-md);
  overflow: hidden;
  background: #e9ecef;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Dark theme overrides for bootstrap */
[data-theme="dark"] .form-control, 
[data-theme="dark"] .form-select {
  background-color: var(--bg-input);
  border-color: var(--border-color);
  color: var(--text-primary);
}

[data-theme="dark"] .form-control::placeholder {
  color: var(--text-muted);
}

[data-theme="dark"] .modal-content {
  background-color: var(--bg-card);
  border-color: var(--border-color);
  color: var(--text-primary);
}

[data-theme="dark"] .modal-header,
[data-theme="dark"] .modal-footer {
  border-color: var(--border-color);
}

[data-theme="dark"] .dropdown-menu {
  background-color: var(--bg-card);
  border-color: var(--border-color);
}

[data-theme="dark"] .dropdown-item {
  color: var(--text-primary);
}

[data-theme="dark"] .dropdown-item:hover {
  background-color: var(--bg-body);
  color: var(--text-primary);
}

[data-theme="dark"] .btn-close {
  filter: invert(1) grayscale(100%) brightness(200%);
}
