/* ==========================================================================
   QuietBits E-Book Library & EPUB Online Reader Styles
   Clean, modern, editorial aesthetic with full dark mode & sepia support
   ========================================================================== */

:root {
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji";
  --font-serif: "Charter", "Bitstream Charter", "Sitka Text", Cambria, Georgia, serif;
  --bg-primary: #f8fafc;
  --bg-card: #ffffff;
  --bg-elevated: #ffffff;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --text-light: #94a3b8;
  --border-color: #e2e8f0;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-subtle: #eff6ff;
  --tag-bg: #f1f5f9;
  --tag-text: #475569;
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-full: 9999px;
  --header-height: 64px;
}

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

body {
  font-family: var(--font-sans);
  background-color: var(--bg-primary);
  color: var(--text-main);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a {
  color: inherit;
  text-decoration: none;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
}

/* Site Layout */
.site-wrapper {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Header */
.header {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border-color);
  padding: 24px 20px;
  position: sticky;
  top: 0;
  z-index: 40;
  box-shadow: var(--shadow-sm);
}

.header-inner {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-icon {
  font-size: 36px;
  line-height: 1;
}

.brand-text h1 {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: #0f172a;
}

.brand-text .subtitle {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 2px;
}

.stat-badge {
  background: var(--accent-subtle);
  border: 1px solid #bfdbfe;
  border-radius: var(--radius-md);
  padding: 8px 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.stat-num {
  font-size: 20px;
  font-weight: 700;
  color: var(--accent);
  line-height: 1.1;
}

.stat-label {
  font-size: 11px;
  color: #3b82f6;
  font-weight: 500;
}

/* Toolbar */
.toolbar {
  padding: 24px 20px 10px;
  max-width: 1200px;
  margin: 0 auto;
  width: 100%;
}

.toolbar-inner {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.search-box {
  position: relative;
  display: flex;
  align-items: center;
  background: var(--bg-card);
  border: 1.5px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0 16px;
  transition: all 0.2s ease;
  box-shadow: var(--shadow-sm);
}

.search-box:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.search-icon {
  font-size: 16px;
  margin-right: 10px;
  opacity: 0.6;
}

.search-box input {
  flex: 1;
  border: none;
  outline: none;
  padding: 12px 0;
  font-size: 15px;
  background: transparent;
  color: var(--text-main);
}

.clear-btn {
  color: var(--text-muted);
  font-size: 14px;
  padding: 4px;
  border-radius: 50%;
}

.clear-btn:hover {
  color: var(--text-main);
}

/* Category Chips */
.category-chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
  scrollbar-width: none;
}

.category-chips::-webkit-scrollbar {
  display: none;
}

.chip {
  padding: 7px 16px;
  border-radius: var(--radius-full);
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  font-size: 13.5px;
  font-weight: 500;
  white-space: nowrap;
  transition: all 0.2s;
}

.chip:hover {
  border-color: #cbd5e1;
  color: var(--text-main);
}

.chip.active {
  background: var(--text-main);
  border-color: var(--text-main);
  color: #ffffff;
}

/* Books Grid */
.main-content {
  flex: 1;
  max-width: 1200px;
  margin: 0 auto;
  padding: 10px 20px 40px;
  width: 100%;
}

.books-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 24px;
  margin-top: 10px;
}

/* Book Card */
.book-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
  box-shadow: var(--shadow-sm);
}

.book-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-lg);
  border-color: #cbd5e1;
}

.card-cover {
  height: 140px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  position: relative;
  overflow: hidden;
  color: #ffffff;
}

/* Card color gradients based on category */
.card-cover.cat-biz {
  background: linear-gradient(135deg, #1e3a8a 0%, #3b82f6 100%);
}
.card-cover.cat-cog {
  background: linear-gradient(135deg, #4c1d95 0%, #8b5cf6 100%);
}
.card-cover.cat-growth {
  background: linear-gradient(135deg, #065f46 0%, #10b981 100%);
}
.card-cover.cat-edu {
  background: linear-gradient(135deg, #9a3412 0%, #f97316 100%);
}
.card-cover.cat-lit {
  background: linear-gradient(135deg, #7c2d12 0%, #b45309 100%);
}
.card-cover.cat-other {
  background: linear-gradient(135deg, #334155 0%, #64748b 100%);
}

.cover-badge {
  display: inline-block;
  align-self: flex-start;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  background: rgba(255, 255, 255, 0.22);
  backdrop-filter: blur(4px);
  padding: 3px 8px;
  border-radius: var(--radius-sm);
  letter-spacing: 0.05em;
}

.cover-title-preview {
  font-size: 16px;
  font-weight: 700;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
}

.card-body {
  padding: 18px;
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.book-title-heading {
  font-size: 15.5px;
  font-weight: 700;
  color: var(--text-main);
  line-height: 1.4;
  margin-bottom: 6px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.book-author-meta {
  font-size: 13px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 12px;
}

.card-meta-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 18px;
}

.meta-tag {
  font-size: 11.5px;
  background: var(--tag-bg);
  color: var(--tag-text);
  padding: 3px 8px;
  border-radius: var(--radius-sm);
  font-weight: 500;
}

.card-actions {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  margin-top: auto;
}

.btn-read-now {
  background: var(--accent);
  color: #ffffff;
  padding: 9px 14px;
  border-radius: var(--radius-md);
  font-size: 13.5px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: background 0.15s ease;
}

.btn-read-now:hover {
  background: var(--accent-hover);
}

.btn-download-file {
  background: #f1f5f9;
  color: #334155;
  padding: 9px 12px;
  border-radius: var(--radius-md);
  font-size: 13px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 4px;
  transition: all 0.15s ease;
}

.btn-download-file:hover {
  background: #e2e8f0;
  color: #0f172a;
}

/* States */
.loading-state, .empty-state {
  grid-column: 1 / -1;
  text-align: center;
  padding: 80px 20px;
  color: var(--text-muted);
}

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid rgba(37, 99, 235, 0.2);
  border-radius: 50%;
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
  margin: 0 auto 16px;
}

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

.empty-icon {
  font-size: 48px;
  margin-bottom: 12px;
}

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

/* Footer */
.footer {
  background: var(--bg-card);
  border-top: 1px solid var(--border-color);
  padding: 24px 20px;
  margin-top: auto;
  font-size: 13px;
  color: var(--text-muted);
  text-align: center;
}

.footer-inner {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.footer-links {
  display: flex;
  justify-content: center;
  gap: 8px;
  color: var(--text-light);
  font-size: 12px;
}

/* ==========================================================================
   READER SPECIFIC STYLES
   ========================================================================== */

.reader-body {
  height: 100vh;
  overflow: hidden;
}

/* Reader Themes */
.theme-default {
  --reader-bg: #ffffff;
  --reader-text: #1e293b;
  --reader-bar-bg: #ffffff;
  --reader-bar-border: #e2e8f0;
  --reader-btn-hover: #f1f5f9;
}

.theme-sepia {
  --reader-bg: #fbf7ee;
  --reader-text: #453424;
  --reader-bar-bg: #f5eedc;
  --reader-bar-border: #e6dac3;
  --reader-btn-hover: #ece3cf;
}

.theme-dark {
  --reader-bg: #18181b;
  --reader-text: #d4d4d8;
  --reader-bar-bg: #27272a;
  --reader-bar-border: #3f3f46;
  --reader-btn-hover: #3f3f46;
}

.reader-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
  background-color: var(--reader-bg);
  color: var(--reader-text);
  transition: background-color 0.25s, color 0.25s;
}

/* Reader Header */
.reader-header {
  height: var(--header-height);
  background: var(--reader-bar-bg);
  border-bottom: 1px solid var(--reader-bar-border);
  padding: 0 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  z-index: 50;
  box-shadow: var(--shadow-sm);
  flex-shrink: 0;
}

.reader-header-left {
  display: flex;
  align-items: center;
  gap: 16px;
  min-width: 0;
}

.back-link {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  font-weight: 500;
  color: var(--reader-text);
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  transition: background 0.15s;
  flex-shrink: 0;
}

.back-link:hover {
  background: var(--reader-btn-hover);
}

.reader-book-title {
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 450px;
}

.reader-header-right {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.reader-tool-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  font-weight: 500;
  color: var(--reader-text);
  border: 1px solid var(--reader-bar-border);
  background: var(--reader-bar-bg);
  transition: all 0.15s;
}

.reader-tool-btn:hover {
  background: var(--reader-btn-hover);
}

.font-controls {
  display: flex;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--reader-bar-border);
}

.font-controls .reader-tool-btn {
  border: none;
  border-radius: 0;
  padding: 6px 10px;
  font-weight: 700;
}

.font-controls .reader-tool-btn:first-child {
  border-right: 1px solid var(--reader-bar-border);
}

.theme-controls {
  display: flex;
  gap: 6px;
  align-items: center;
}

.theme-btn {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid transparent;
  transition: transform 0.15s, border-color 0.15s;
}

.theme-btn.active {
  border-color: var(--accent);
  transform: scale(1.15);
}

.theme-btn-light {
  background: #ffffff;
  box-shadow: inset 0 0 0 1px #cbd5e1;
}

.theme-btn-sepia {
  background: #fbf7ee;
  box-shadow: inset 0 0 0 1px #d6c7ab;
}

.theme-btn-dark {
  background: #27272a;
  box-shadow: inset 0 0 0 1px #52525b;
}

.reader-download-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 12px;
  background: var(--accent);
  color: #ffffff;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  transition: background 0.15s;
}

.reader-download-btn:hover {
  background: var(--accent-hover);
}

/* Reader Main Viewer */
.reader-main {
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.viewer-area {
  width: 100%;
  max-width: 860px;
  height: 100%;
  margin: 0 auto;
}

.nav-arrow {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 48px;
  height: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 36px;
  font-weight: 300;
  color: var(--reader-text);
  opacity: 0.25;
  transition: opacity 0.2s, background 0.2s;
  z-index: 20;
  border-radius: var(--radius-md);
  user-select: none;
}

.nav-arrow:hover {
  opacity: 0.9;
  background: rgba(0, 0, 0, 0.05);
}

.nav-prev {
  left: 12px;
}

.nav-next {
  right: 12px;
}

.reader-loading {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--reader-bg);
  z-index: 30;
  gap: 12px;
}

/* Reader Footer */
.reader-footer {
  height: 38px;
  background: var(--reader-bar-bg);
  border-top: 1px solid var(--reader-bar-border);
  padding: 0 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text-muted);
  flex-shrink: 0;
}

.reader-chapter-name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 60%;
}

/* TOC Overlay Drawer */
.toc-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(2px);
  z-index: 100;
  display: flex;
}

.toc-drawer {
  width: 320px;
  max-width: 85vw;
  background: var(--reader-bar-bg);
  height: 100%;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--reader-bar-border);
  animation: slideIn 0.2s ease-out;
}

@keyframes slideIn {
  from { transform: translateX(-100%); }
  to { transform: translateX(0); }
}

.toc-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--reader-bar-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.toc-header h3 {
  font-size: 16px;
  font-weight: 600;
}

.close-toc-btn {
  font-size: 16px;
  color: var(--text-muted);
  padding: 4px;
}

.toc-content {
  flex: 1;
  overflow-y: auto;
  padding: 12px 0;
}

.toc-item {
  display: block;
  padding: 10px 20px;
  font-size: 13.5px;
  color: var(--reader-text);
  border-bottom: 1px solid rgba(0, 0, 0, 0.04);
  transition: background 0.15s;
}

.toc-item:hover {
  background: var(--reader-btn-hover);
  color: var(--accent);
}

/* Responsive adjustments */
@media (max-width: 768px) {
  .brand-text .subtitle {
    display: none;
  }
  .header-stats {
    display: none;
  }
  .books-grid {
    grid-template-columns: 1fr;
  }
  .reader-book-title {
    max-width: 160px;
  }
  .btn-text {
    display: none;
  }
  .nav-arrow {
    width: 36px;
    height: 60px;
    font-size: 28px;
  }
}
