/*
  Design tokens — "cloth-bound book" identity.
  Navy (cover cloth) + gold (foil stamping) + a calmer, less glary
  background than a stark near-white. Includes a full dark mode, driven by
  Bootstrap 5.3's built-in [data-bs-theme] color-mode system.

  Token strategy: brand-literal tokens (--ink-900, --gold-500, etc.) never
  change between light/dark — they're the fixed identity colors used on
  permanently-dark elements like the header/footer. Semantic tokens
  (--bg-page, --text-primary, etc.) DO change between modes — everything
  that should look different in dark mode references one of these instead.
*/
:root {
  /* Brand-literal (fixed regardless of light/dark mode) */
  --ink-900: #10162B;
  --ink-800: #171E38;
  --ink-700: #232C4D;
  --gold-500: #C9A227;
  --gold-400: #D9B94A;
  --burgundy-600: #7A2E2E;
  --success-600: #2E7A4F;
  --on-dark: #F4F5F7; /* text color for use on permanently-dark elements (header, active sidebar pill) */

  --font-display: 'Fraunces', 'Georgia', serif;
  --font-body: 'Inter', system-ui, -apple-system, sans-serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, monospace;

  --radius-sm: 4px;
  --radius-md: 8px;
  --shadow-card: 0 1px 2px rgba(16, 22, 43, 0.06), 0 4px 16px rgba(16, 22, 43, 0.06);

  /* Semantic — LIGHT mode. Deliberately calmer than a stark near-white
     background: large bright fields are a real eye-strain / light-
     sensitivity issue, not just a style preference. */
  --bg-page: #E3E5E9;
  --bg-surface: #FFFFFF;
  --bg-placeholder: #ECEEF2;
  --text-primary: #10162B;
  --text-secondary: #4A5169;
  --text-tertiary: #8890A6;
  --border-subtle: #DBDEE3;

  /* Reading pane — warm, paper-like, not stark white (classic e-reader
     "sepia" treatment; easier on the eyes for long reading sessions). */
  --reading-bg: #FBF6EC;
  --reading-text: #2B2418;
  --reading-border: #E8DFC8;
}

/* Semantic — DARK mode. Soft near-black rather than pure black (pure
   black behind bright content causes halation/glare for many light-
   sensitive readers, the same problem in reverse). Off-white text rather
   than pure white for the same reason. */
[data-bs-theme="dark"] {
  --bg-page: #15171C;
  --bg-surface: #1D2027;
  --bg-placeholder: #23262E;
  --text-primary: #E7E8EC;
  --text-secondary: #A2A8B5;
  --text-tertiary: #767C89;
  --border-subtle: #2A2D35;

  --reading-bg: #1B1C1F;
  --reading-text: #D8D3C4;
  --reading-border: #302B22;
}

body {
  background-color: var(--bg-page);
  color: var(--text-primary);
  font-family: var(--font-body);
  font-feature-settings: "liga" 1;
}

h1, h2, h3, h4, .display-font {
  font-family: var(--font-display);
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text-primary);
}

.price, .money {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

.text-muted { color: var(--text-secondary) !important; }

/* ---------- Header ---------- */
.site-header {
  background: var(--ink-900);
  border-bottom: 1px solid rgba(255,255,255,0.06);
}

.site-header .navbar-brand {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.35rem;
  color: var(--on-dark) !important;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.site-header .navbar-brand svg { flex-shrink: 0; }

.site-header .nav-link {
  color: rgba(244,245,247,0.82) !important;
  font-weight: 500;
  font-size: 0.95rem;
  position: relative;
  padding-bottom: 0.35rem !important;
}

.site-header .nav-link:hover {
  color: var(--on-dark) !important;
}

/* signature: active nav item gets a small gold "bookmark ribbon" tab */
.site-header .nav-link.active {
  color: var(--on-dark) !important;
}

.site-header .nav-link.active::after {
  content: "";
  position: absolute;
  bottom: -1px;
  left: 0.2rem;
  width: 14px;
  height: 4px;
  background: var(--gold-500);
  clip-path: polygon(0 0, 100% 0, 100% 100%, 50% 70%, 0 100%);
}

.site-header .btn-cart {
  color: var(--on-dark);
  border: 1px solid rgba(244,245,247,0.25);
  border-radius: var(--radius-sm);
}
.site-header .btn-cart:hover {
  border-color: var(--gold-500);
  color: var(--gold-400);
}

.cart-badge {
  background: var(--gold-500);
  color: var(--ink-900);
  font-weight: 700;
}

/* Theme toggle button, sits in the header */
.theme-toggle {
  background: transparent;
  border: 1px solid rgba(244,245,247,0.25);
  color: var(--on-dark);
  border-radius: var(--radius-sm);
  width: 34px;
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease;
}
.theme-toggle:hover {
  border-color: var(--gold-500);
  color: var(--gold-400);
}
.theme-toggle .bi-sun-fill { display: none; }
[data-bs-theme="dark"] .theme-toggle .bi-moon-stars-fill { display: none; }
[data-bs-theme="dark"] .theme-toggle .bi-sun-fill { display: inline; }

/* ---------- Footer ---------- */
.site-footer {
  background: var(--ink-900);
  color: rgba(244,245,247,0.7);
}
.site-footer a {
  color: rgba(244,245,247,0.8);
  text-decoration: none;
}
.site-footer a:hover { color: var(--gold-400); }
.site-footer .footer-brand {
  font-family: var(--font-display);
  color: var(--on-dark);
  font-size: 1.15rem;
  font-weight: 700;
}
.site-footer hr { border-color: rgba(244,245,247,0.1); }

/* ---------- Sidebar ---------- */
/* Deliberately the same permanent navy as the header/footer — sidebar is
   "chrome" (navigation), not page content, so unlike the main content area
   it does NOT switch with the light/dark toggle. This also makes the
   separation from the main content area unmistakable, not just a subtle
   shade difference. */
.app-sidebar {
  background: var(--ink-900);
  border-right: none;
  min-height: calc(100vh - 64px);
}

/* Independent scrolling for sidebar + main content, desktop only (matches
   the sidebar's own d-lg-block breakpoint — on mobile the sidebar becomes
   a collapsible menu inline in the page, so normal page scroll applies
   there instead). The header is sticky-top, so 64px is its real height;
   everything below it is carved into two separately-scrolling panes. */
@media (min-width: 992px) {
  .app-shell-row {
    height: calc(100vh - 64px);
  }
  .app-shell-row > .app-sidebar {
    min-height: 0;
    height: 100%;
    overflow-y: auto;
    position: sticky;
    top: 0;
  }
  .app-shell-row > .app-main-scroll {
    height: 100%;
    overflow-y: auto;
  }
}
.app-sidebar .nav-link {
  color: rgba(244,245,247,0.72);
  border-radius: var(--radius-sm);
  font-weight: 500;
  padding: 0.55rem 0.85rem;
  margin-bottom: 0.15rem;
  border-left: 3px solid transparent;
}
.app-sidebar .nav-link:hover {
  background: rgba(244,245,247,0.06);
  color: var(--on-dark);
}
.app-sidebar .nav-link.active {
  background: rgba(244,245,247,0.08);
  color: var(--on-dark);
  border-left: 3px solid var(--gold-500);
}
.app-sidebar .nav-section-label {
  text-transform: uppercase;
  font-size: 0.7rem;
  letter-spacing: 0.06em;
  color: rgba(244,245,247,0.38);
  font-weight: 600;
  padding: 0.75rem 0.85rem 0.25rem;
}
.app-sidebar hr {
  border-color: rgba(244,245,247,0.1);
}
.app-sidebar .sidebar-meta {
  color: rgba(244,245,247,0.5);
}

/* ---------- Cards / buttons ---------- */
.book-card {
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-card);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  background: var(--bg-surface);
  max-width: 170px;
  margin: 0 auto;
}
.book-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 8px 24px rgba(16,22,43,0.12);
}
.book-card .cover-wrap {
  aspect-ratio: 2 / 3;
  overflow: hidden;
  border-radius: var(--radius-md) var(--radius-md) 0 0;
  background: var(--bg-placeholder);
  position: relative;
}
.book-card img {
  width: 100%; height: 100%; object-fit: cover;
}

.btn-primary {
  background: var(--ink-900);
  border-color: var(--ink-900);
}
.btn-primary:hover, .btn-primary:focus {
  background: var(--ink-700);
  border-color: var(--ink-700);
}
.btn-gold {
  background: var(--gold-500);
  border-color: var(--gold-500);
  color: var(--ink-900);
  font-weight: 600;
}
.btn-gold:hover { background: var(--gold-400); color: var(--ink-900); }

.badge-locked {
  background: var(--burgundy-600);
  color: #fff;
}
.badge-free {
  background: var(--success-600);
  color: #fff;
}

/* ---------- Reading pane ---------- */
/* A distinct "paper" surface for the chapter text itself — warm/sepia in
   light mode, soft warm-dark in dark mode — rather than reading long-form
   text straight off the page background. This is the single biggest
   comfort lever for a reading-heavy site. */
.reading-surface {
  background: var(--reading-bg);
  color: var(--reading-text);
  border: 1px solid var(--reading-border);
  border-radius: var(--radius-md);
  padding: 2rem 1.75rem;
}
@media (min-width: 768px) {
  .reading-surface { padding: 3rem 3.5rem; }
}

/* Visible keyboard focus (accessibility) */
a:focus-visible, button:focus-visible, input:focus-visible, .nav-link:focus-visible {
  outline: 2px solid var(--gold-500);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  .book-card { transition: none; }
}

/* ---------- Floating WhatsApp button ---------- */
.whatsapp-float {
  position: fixed;
  bottom: 22px;
  right: 22px;
  z-index: 1040;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: #25D366;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.6rem;
  box-shadow: 0 4px 14px rgba(0,0,0,0.25);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  text-decoration: none;
}
.whatsapp-float:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 20px rgba(0,0,0,0.3);
  color: #fff;
}
@media (max-width: 576px) {
  .whatsapp-float {
    width: 50px;
    height: 50px;
    bottom: 16px;
    right: 16px;
    font-size: 1.4rem;
  }
}
@media (prefers-reduced-motion: reduce) {
  .whatsapp-float { transition: none; }
}

/* ---------- Pagination ---------- */
/* Bootstrap's default pagination is sized for a marketing page, not a
   dense admin list — this shrinks it everywhere so "Previous/Next"
   doesn't visually dominate the page. */
.pagination {
  gap: 0.25rem;
  flex-wrap: wrap;
}
.pagination .page-link {
  padding: 0.35rem 0.65rem;
  font-size: 0.82rem;
  color: var(--text-primary);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
}
.pagination .page-link:hover {
  background: var(--bg-placeholder);
  color: var(--text-primary);
}
.pagination .page-item.active .page-link {
  background: var(--ink-900);
  border-color: var(--ink-900);
  color: var(--on-dark);
}
.pagination .page-item.disabled .page-link {
  background: transparent;
  color: var(--text-tertiary);
  border-color: var(--border-subtle);
}