/* === RESET & BASE === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg-primary: #2C1810;
  --bg-secondary: #3E2723;
  --bg-shelf: #4E342E;
  --bg-card: #3E2723;
  --text-primary: #FFF8E1;
  --text-secondary: #D7CCC8;
  --text-muted: #A1887F;
  --border: #5D4037;
  --shelf-wood: linear-gradient(180deg, #5D4037 0%, #4E342E 40%, #3E2723 100%);
  --shelf-edge: linear-gradient(180deg, #8D6E63 0%, #6D4C41 50%, #4E342E 100%);
  --shadow: rgba(0,0,0,0.4);
  --cream: #FFF8E1;
  --accent: #FFAB40;
}

[data-theme="light"] {
  --bg-primary: #EFEBE9;
  --bg-secondary: #FFF8E1;
  --bg-shelf: #D7CCC8;
  --bg-card: #FFFFFF;
  --text-primary: #3E2723;
  --text-secondary: #5D4037;
  --text-muted: #8D6E63;
  --border: #BCAAA4;
  --shelf-wood: linear-gradient(180deg, #BCAAA4 0%, #D7CCC8 40%, #EFEBE9 100%);
  --shelf-edge: linear-gradient(180deg, #A1887F 0%, #BCAAA4 50%, #D7CCC8 100%);
  --shadow: rgba(0,0,0,0.12);
}

html { font-size: 16px; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  padding-top: 120px;
  padding-bottom: 60px;
}

/* === TOP BAR === */
.top-bar {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 100;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(10px);
}
.top-bar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 20px;
  max-width: 1400px;
  margin: 0 auto;
}
.logo {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--cream);
  letter-spacing: -0.5px;
}
[data-theme="light"] .logo { color: var(--text-primary); }

.view-tabs { display: flex; gap: 4px; }
.tab {
  padding: 6px 16px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 500;
  transition: all 0.2s;
}
.tab:hover { background: var(--border); color: var(--text-primary); }
.tab.active {
  background: var(--accent);
  color: #1a1a1a;
  border-color: var(--accent);
}

.theme-toggle {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 10px;
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 1.1rem;
  transition: all 0.2s;
}
.theme-toggle:hover { background: var(--border); }

/* === SEARCH === */
.search-bar {
  display: flex;
  align-items: center;
  padding: 8px 20px 10px;
  max-width: 1400px;
  margin: 0 auto;
  gap: 8px;
}
.search-icon { font-size: 1rem; opacity: 0.5; }
.search-bar input {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 0.9rem;
  outline: none;
  transition: border-color 0.2s;
}
.search-bar input:focus { border-color: var(--accent); }
.search-bar input::placeholder { color: var(--text-muted); }
.search-clear {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 1.3rem;
  cursor: pointer;
  padding: 0 6px;
  display: none;
}
.search-clear.visible { display: block; }
.search-count {
  font-size: 0.8rem;
  color: var(--text-muted);
  white-space: nowrap;
  min-width: 80px;
  text-align: right;
}

/* === VIEWS === */
.view { display: none; max-width: 1400px; margin: 0 auto; padding: 0 20px; }
.view.active { display: block; }

/* === SHELF VIEW === */
.shelf-group {
  margin-bottom: 8px;
}
.shelf-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0 4px;
  cursor: pointer;
  user-select: none;
}
.shelf-header:hover .shelf-label { color: var(--accent); }
.shelf-toggle {
  font-size: 0.7rem;
  color: var(--text-muted);
  transition: transform 0.2s;
  width: 16px;
}
.shelf-group.collapsed .shelf-toggle { transform: rotate(-90deg); }
.shelf-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
  transition: color 0.2s;
}
.shelf-count {
  font-size: 0.75rem;
  color: var(--text-muted);
  background: var(--bg-shelf);
  padding: 2px 8px;
  border-radius: 10px;
}
.shelf-color-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.shelf-row {
  display: flex;
  align-items: flex-end;
  padding: 12px 12px 0;
  min-height: 100px;
  overflow-x: auto;
  overflow-y: hidden;
  gap: 1.5px;
  background: var(--shelf-wood);
  border-radius: 4px 4px 0 0;
  position: relative;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
.shelf-row::-webkit-scrollbar { height: 4px; }
.shelf-row::-webkit-scrollbar-track { background: transparent; }
.shelf-row::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.shelf-edge {
  height: 10px;
  background: var(--shelf-edge);
  border-radius: 0 0 4px 4px;
  box-shadow: 0 3px 8px var(--shadow);
  margin-bottom: 4px;
}
.shelf-group.collapsed .shelf-row,
.shelf-group.collapsed .shelf-edge { display: none; }

/* Book Spines */
.spine {
  flex-shrink: 0;
  border-radius: 1.5px 2px 0 0;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s, filter 0.15s;
  position: relative;
  box-shadow: 1px 0 2px rgba(0,0,0,0.3), inset 1px 0 0 rgba(255,255,255,0.08);
}
.spine::after {
  content: '';
  position: absolute;
  top: 4px; bottom: 4px;
  left: 50%;
  width: 1px;
  background: rgba(255,255,255,0.06);
}
.spine:hover {
  transform: translateY(-6px) scale(1.05);
  box-shadow: 2px 2px 10px rgba(0,0,0,0.5);
  filter: brightness(1.15);
  z-index: 10;
}
.spine.pending {
  border: 1px dashed var(--accent);
  opacity: 0.7;
}

/* === GRID VIEW === */
.grid-controls {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  flex-wrap: wrap;
  align-items: center;
}
.grid-controls label {
  font-size: 0.8rem;
  color: var(--text-muted);
}
.grid-controls select {
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg-card);
  color: var(--text-primary);
  font-size: 0.8rem;
}
.book-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 12px;
}
.book-card {
  background: var(--bg-card);
  border-radius: 8px;
  padding: 14px 14px 14px 18px;
  border-left: 4px solid #888;
  box-shadow: 0 2px 6px var(--shadow);
  transition: transform 0.15s, box-shadow 0.15s;
  cursor: default;
}
.book-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px var(--shadow);
}
.book-card .book-title {
  font-family: Georgia, 'Times New Roman', serif;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 4px;
  line-height: 1.3;
}
.book-card .book-author {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-bottom: 8px;
}
.book-card .book-meta {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.badge {
  font-size: 0.65rem;
  padding: 2px 8px;
  border-radius: 10px;
  font-weight: 500;
  color: #fff;
}
.badge-pending {
  background: var(--accent) !important;
  color: #1a1a1a !important;
}
.book-card .book-notes {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 6px;
  font-style: italic;
}

/* === STATS VIEW === */
.stats-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 28px;
}
.stat-card {
  background: var(--bg-card);
  border-radius: 10px;
  padding: 18px;
  text-align: center;
  box-shadow: 0 2px 6px var(--shadow);
}
.stat-number {
  font-size: 2.2rem;
  font-weight: 800;
  color: var(--accent);
  line-height: 1;
}
.stat-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 6px;
}
.stats-section {
  margin-bottom: 28px;
}
.stats-section h3 {
  font-size: 1rem;
  color: var(--text-secondary);
  margin-bottom: 12px;
  font-weight: 600;
}
.bar-chart { display: flex; flex-direction: column; gap: 6px; }
.bar-row {
  display: flex;
  align-items: center;
  gap: 10px;
}
.bar-label {
  font-size: 0.78rem;
  color: var(--text-secondary);
  min-width: 140px;
  text-align: right;
  flex-shrink: 0;
}
.bar-track {
  flex: 1;
  height: 22px;
  background: var(--bg-shelf);
  border-radius: 4px;
  overflow: hidden;
  position: relative;
}
.bar-fill {
  height: 100%;
  border-radius: 4px;
  transition: width 0.5s ease;
  display: flex;
  align-items: center;
  padding-left: 8px;
}
.bar-value {
  font-size: 0.7rem;
  color: #fff;
  font-weight: 600;
  text-shadow: 0 1px 2px rgba(0,0,0,0.3);
}

/* === TOOLTIP === */
.tooltip {
  position: fixed;
  z-index: 200;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
  max-width: 280px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
  box-shadow: 0 4px 16px var(--shadow);
}
.tooltip.visible { opacity: 1; }
.tooltip .tt-title {
  font-family: Georgia, serif;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 3px;
}
.tooltip .tt-author {
  font-size: 0.78rem;
  color: var(--text-secondary);
}
.tooltip .tt-category {
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-top: 4px;
}
.tooltip .tt-notes {
  font-size: 0.7rem;
  color: var(--accent);
  margin-top: 3px;
  font-style: italic;
}

/* === MODAL === */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 300;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
}
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}
.modal-header h2 {
  font-size: 1.1rem;
  color: var(--text-primary);
}
.modal-close {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 1.5rem;
  cursor: pointer;
}
.form-group {
  margin-bottom: 12px;
}
.form-group label {
  display: block;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 4px;
}
.form-group input, .form-group select {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 0.85rem;
}
.form-note {
  font-size: 0.73rem;
  color: var(--text-muted);
  margin: 12px 0;
  font-style: italic;
}
.btn-submit {
  width: 100%;
  padding: 10px;
  border: none;
  border-radius: 6px;
  background: var(--accent);
  color: #1a1a1a;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: filter 0.2s;
}
.btn-submit:hover { filter: brightness(1.1); }

/* === FAB === */
.fab {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #1a1a1a;
  font-size: 1.6rem;
  font-weight: 300;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(0,0,0,0.3);
  transition: transform 0.2s, box-shadow 0.2s;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
}
.fab:hover { transform: scale(1.1); box-shadow: 0 6px 20px rgba(0,0,0,0.4); }

/* === FOOTER === */
.footer {
  text-align: center;
  padding: 16px;
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* === RESPONSIVE === */
@media (max-width: 768px) {
  body { padding-top: 130px; }
  .top-bar-inner { padding: 8px 12px; }
  .logo { font-size: 1rem; }
  .tab { padding: 5px 10px; font-size: 0.78rem; }
  .search-bar { padding: 6px 12px 8px; }
  .view { padding: 0 12px; }
  .book-grid { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 8px; }
  .bar-label { min-width: 90px; font-size: 0.7rem; }
  .stats-summary { grid-template-columns: repeat(2, 1fr); }
  .shelf-row { padding: 8px 8px 0; }
}

@media (max-width: 480px) {
  .book-grid { grid-template-columns: 1fr; }
  .stats-summary { grid-template-columns: repeat(2, 1fr); }
  .stat-number { font-size: 1.6rem; }
}

/* === ANIMATIONS === */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
.shelf-group { animation: fadeIn 0.3s ease both; }
.book-card { animation: fadeIn 0.2s ease both; }
.stat-card { animation: fadeIn 0.3s ease both; }

/* No results */
.no-results {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
  font-size: 1rem;
}
