/* =====================================================
   E-Library — Design System
   ===================================================== */
:root {
  --primary: #4f46e5;
  --primary-dark: #4338ca;
  --primary-light: #eef2ff;
  --accent: #0ea5e9;
  --ink-900: #0f172a;
  --ink-700: #334155;
  --ink-500: #64748b;
  --ink-300: #cbd5e1;
  --ink-100: #f1f5f9;
  --surface: #ffffff;
  --bg: #f8fafc;
  --success: #16a34a;
  --danger: #dc2626;
  --warning: #d97706;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 4px 16px rgba(15, 23, 42, 0.08);
  --shadow-lg: 0 12px 32px rgba(15, 23, 42, 0.12);
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  color: var(--ink-900);
  background: var(--bg);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-dark); }
img { max-width: 100%; display: block; }
.container { max-width: 1180px; margin: 0 auto; padding: 0 24px; }
h1, h2, h3, h4 { font-weight: 700; line-height: 1.25; margin: 0 0 12px; color: var(--ink-900); }
p { margin: 0 0 12px; color: var(--ink-700); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 11px 22px; border-radius: var(--radius-sm); font-weight: 600; font-size: 0.95rem;
  border: 1px solid transparent; cursor: pointer; transition: all 0.15s ease;
  text-decoration: none;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-outline { background: transparent; border-color: var(--ink-300); color: var(--ink-700); }
.btn-outline:hover { border-color: var(--primary); color: var(--primary); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #b91c1c; }
.btn-sm { padding: 7px 14px; font-size: 0.85rem; }
.btn-block { width: 100%; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---------- Header ---------- */
.site-header {
  background: var(--surface); border-bottom: 1px solid var(--ink-100);
  position: sticky; top: 0; z-index: 50; box-shadow: var(--shadow-sm);
}
.header-inner {
  display: flex; align-items: center; gap: 24px; height: 72px;
}
.logo {
  display: flex; align-items: center; gap: 8px; font-weight: 800; font-size: 1.25rem;
  color: var(--ink-900); white-space: nowrap;
}
.logo-mark { font-size: 1.4rem; }
.header-search {
  flex: 1; display: flex; max-width: 480px; background: var(--ink-100);
  border-radius: 999px; padding: 4px 4px 4px 16px; align-items: center;
}
.header-search input {
  flex: 1; border: none; background: transparent; outline: none; font-size: 0.92rem; font-family: var(--font);
  padding: 8px 0; color: var(--ink-900);
}
.header-search button {
  border: none; background: var(--primary); color: #fff; width: 36px; height: 36px;
  border-radius: 50%; display: flex; align-items: center; justify-content: center; cursor: pointer;
}
.main-nav { display: flex; gap: 24px; align-items: center; margin-left: auto; }
.main-nav a { color: var(--ink-700); font-weight: 500; font-size: 0.95rem; }
.main-nav a:hover { color: var(--primary); }
.nav-admin-link {
  border: 1px solid var(--ink-300); padding: 8px 16px; border-radius: 999px !important;
}
.nav-toggle { display: none; background: none; border: none; font-size: 1.4rem; cursor: pointer; }

@media (max-width: 860px) {
  .header-search { order: 3; flex: 1 1 100%; margin: 12px 0; }
  .header-inner { flex-wrap: wrap; height: auto; padding: 12px 24px; }
  .main-nav { display: none; }
  .main-nav.open { display: flex; flex-direction: column; width: 100%; order: 4; gap: 12px; padding-bottom: 12px; }
  .nav-toggle { display: block; margin-left: auto; order: 2; }
}

/* ---------- Hero ---------- */
.hero {
  background: linear-gradient(135deg, var(--primary) 0%, var(--accent) 100%);
  color: #fff; padding: 72px 0 88px; text-align: center;
}
.hero h1 { color: #fff; font-size: 2.4rem; margin-bottom: 12px; }
.hero p { color: rgba(255,255,255,0.9); max-width: 560px; margin: 0 auto 8px; font-size: 1.05rem; }
.hero .hero-stats { display: flex; justify-content: center; gap: 40px; margin-top: 32px; flex-wrap: wrap; }
.hero .hero-stats div strong { display: block; font-size: 1.8rem; }
.hero .hero-stats div span { font-size: 0.85rem; opacity: 0.85; }

/* ---------- Section ---------- */
.section { padding: 56px 0; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 28px; flex-wrap: wrap; gap: 12px; }
.section-head h2 { margin: 0; font-size: 1.5rem; }
.section-head .see-all { font-weight: 600; font-size: 0.9rem; }

/* ---------- Category chips ---------- */
.chip-row { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 32px; }
.chip {
  padding: 8px 16px; border-radius: 999px; background: var(--surface); border: 1px solid var(--ink-300);
  font-size: 0.85rem; font-weight: 600; color: var(--ink-700);
}
.chip.active, .chip:hover { background: var(--primary); border-color: var(--primary); color: #fff; }

/* ---------- All-categories grid (categories.php) ---------- */
.category-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 18px;
}
.category-card {
  display: flex; flex-direction: column; gap: 6px; padding: 20px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--ink-100); box-shadow: var(--shadow-sm);
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}
.category-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-md); border-color: var(--primary); }
.category-card-name { font-weight: 700; font-size: 1rem; color: var(--ink-900); }
.category-card-count { font-size: 0.8rem; color: var(--ink-500); }

@media (max-width: 480px) {
  .category-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; }
  .category-card { padding: 16px; }
}

/* ---------- Book grid & cards ---------- */
.book-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 24px;
}
.book-card {
  background: var(--surface); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow-sm);
  border: 1px solid var(--ink-100); transition: transform 0.18s ease, box-shadow 0.18s ease; display: flex; flex-direction: column;
}
.book-card:hover { transform: translateY(-4px); box-shadow: var(--shadow-lg); }
.book-cover {
  aspect-ratio: 3/4; width: 100%; background: linear-gradient(135deg, var(--primary-light), var(--ink-100));
  display: flex; align-items: center; justify-content: center; overflow: hidden; position: relative;
}
.book-cover img { width: 100%; height: 100%; object-fit: cover; }
.book-cover .placeholder-icon { font-size: 2.6rem; opacity: 0.4; }
.book-card-body { padding: 14px 16px 18px; flex: 1; display: flex; flex-direction: column; }
.book-card-body h3 { font-size: 0.98rem; margin-bottom: 4px; }
.book-card-body h3 a { color: var(--ink-900); }
.book-card-body .book-author { font-size: 0.82rem; color: var(--ink-500); margin-bottom: 8px; }
.book-card-body .book-category {
  display: inline-block; font-size: 0.72rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--primary); background: var(--primary-light); padding: 3px 8px; border-radius: 6px; margin-bottom: 10px; width: fit-content;
}
.book-card-body .card-footer { margin-top: auto; display: flex; justify-content: space-between; align-items: center; }
.empty-state { text-align: center; padding: 64px 20px; color: var(--ink-500); }
.empty-state .icon { font-size: 3rem; margin-bottom: 12px; }

/* ---------- Book detail page ---------- */
.book-detail { display: grid; grid-template-columns: 300px 1fr; gap: 40px; padding: 48px 0; }
.book-detail-cover { border-radius: var(--radius); box-shadow: var(--shadow-md); overflow: hidden; aspect-ratio: 3/4; }
.book-detail-cover img { width: 100%; height: 100%; object-fit: cover; }
.book-detail-cover .placeholder-icon { font-size: 4rem; }
.book-detail-info .book-category { margin-bottom: 12px; }
.book-detail-info h1 { font-size: 1.9rem; }
.book-meta-row { display: flex; gap: 24px; margin: 16px 0 24px; color: var(--ink-500); font-size: 0.88rem; flex-wrap: wrap; }
.book-meta-row span { display: flex; align-items: center; gap: 6px; }
.book-detail-info .actions { display: flex; gap: 12px; margin-top: 24px; flex-wrap: wrap; }
@media (max-width: 720px) { .book-detail { grid-template-columns: 1fr; } .book-detail-cover { max-width: 220px; margin: 0 auto; } }

/* ---------- Forms (shared with admin) ---------- */
.form-group { margin-bottom: 20px; }
.form-group label { display: block; font-weight: 600; font-size: 0.88rem; margin-bottom: 6px; color: var(--ink-700); }
.form-group .hint { font-size: 0.78rem; color: var(--ink-500); margin-top: 4px; }
input[type=text], input[type=password], input[type=email], input[type=number], input[type=file], textarea, select {
  width: 100%; padding: 11px 14px; border: 1px solid var(--ink-300); border-radius: var(--radius-sm);
  font-family: var(--font); font-size: 0.94rem; background: var(--surface); color: var(--ink-900);
  transition: border-color 0.15s;
}
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-light); }
textarea { resize: vertical; min-height: 100px; }

/* ---------- Alerts ---------- */
.alert { padding: 13px 18px; border-radius: var(--radius-sm); margin-bottom: 20px; font-size: 0.92rem; font-weight: 500; }
.alert-success { background: #ecfdf5; color: #047857; border: 1px solid #a7f3d0; }
.alert-error { background: #fef2f2; color: #b91c1c; border: 1px solid #fecaca; }
.alert-info { background: var(--primary-light); color: var(--primary-dark); border: 1px solid #c7d2fe; }

/* ---------- Auth (login) page ---------- */
.auth-wrapper { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--bg); padding: 20px; }
.auth-card { background: var(--surface); padding: 40px; border-radius: var(--radius); box-shadow: var(--shadow-lg); width: 100%; max-width: 400px; }
.auth-card .logo { justify-content: center; margin-bottom: 24px; font-size: 1.4rem; }
.auth-card h1 { text-align: center; font-size: 1.3rem; }
.auth-card p.sub { text-align: center; margin-bottom: 28px; font-size: 0.88rem; }
.auth-back { text-align: center; margin-top: 20px; font-size: 0.85rem; }

/* ---------- Footer ---------- */
.site-footer { background: var(--ink-900); color: var(--ink-300); padding: 32px 0; margin-top: 40px; }
.footer-inner { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 12px; font-size: 0.85rem; }
.footer-inner a { color: var(--ink-300); }
.footer-inner a:hover { color: #fff; }

/* ---------- Pagination ---------- */
.pagination { display: flex; justify-content: center; gap: 8px; margin-top: 40px; }
.pagination a, .pagination span {
  padding: 8px 14px; border-radius: var(--radius-sm); border: 1px solid var(--ink-300); font-size: 0.88rem; color: var(--ink-700);
}
.pagination a:hover { border-color: var(--primary); color: var(--primary); }
.pagination .current { background: var(--primary); color: #fff; border-color: var(--primary); }

/* =====================================================
   PDF Reader
   ===================================================== */
.reader-page { background: #1e293b; height: 100vh; overflow: hidden; position: relative; }
.reader-toolbar {
  background: #0f172a; color: #fff; display: flex; align-items: center; gap: 10px;
  padding: 10px 18px; flex-wrap: wrap; position: absolute; top: 0; left: 0; right: 0; z-index: 40;
  box-shadow: 0 2px 8px rgba(0,0,0,0.3); transition: transform 0.28s ease;
}
.reader-toolbar.toolbar-hidden { transform: translateY(-100%); }
.reader-toolbar .rt-title { font-weight: 600; font-size: 0.9rem; margin-right: auto; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 240px; }
.reader-toolbar .rt-back { color: #fff; font-size: 1.2rem; text-decoration: none; padding: 4px 8px; border-radius: 6px; }
.reader-toolbar .rt-back:hover { background: rgba(255,255,255,0.1); }
.rt-group { display: flex; align-items: center; gap: 4px; background: rgba(255,255,255,0.06); border-radius: 8px; padding: 4px; }
.rt-btn {
  background: transparent; border: none; color: #fff; width: 34px; height: 34px; border-radius: 6px;
  display: flex; align-items: center; justify-content: center; cursor: pointer; font-size: 1rem;
}
.rt-btn:hover:not(:disabled) { background: rgba(255,255,255,0.15); }
.rt-btn:disabled { opacity: 0.35; cursor: not-allowed; }
.rt-page-input { width: 46px; text-align: center; padding: 6px 4px; border-radius: 6px; border: none; font-size: 0.85rem; }
.rt-page-of { font-size: 0.82rem; opacity: 0.85; white-space: nowrap; }
.rt-zoom-level { font-size: 0.8rem; min-width: 42px; text-align: center; opacity: 0.9; }
.rt-search-box { display: flex; align-items: center; background: rgba(255,255,255,0.06); border-radius: 8px; padding: 2px 4px 2px 12px; gap: 6px; }
.rt-search-box input { background: transparent; border: none; color: #fff; outline: none; font-size: 0.85rem; width: 140px; padding: 6px 0; }
.rt-search-box input::placeholder { color: rgba(255,255,255,0.5); }
.rt-match-count { font-size: 0.78rem; opacity: 0.75; white-space: nowrap; padding-right: 4px; }

.reader-body {
  position: absolute; inset: 0; overflow-y: auto; overflow-x: auto;
  padding-top: var(--toolbar-h, 64px); box-sizing: border-box; transition: padding-top 0.28s ease;
  -webkit-overflow-scrolling: touch;
}
.reader-body.toolbar-hidden { padding-top: 0; }

.pdf-pages-container { display: flex; flex-direction: column; align-items: center; gap: 18px; padding: 18px 16px 90px; min-height: 100%; }
.pdf-page-wrap { position: relative; box-shadow: 0 8px 30px rgba(0,0,0,0.4); background: #fff; flex-shrink: 0; }
.pdf-page-wrap canvas { display: block; width: 100%; height: 100%; }
.pdf-page-wrap .page-loading-hint {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  color: var(--ink-500); font-size: 0.8rem; background: #f1f5f9;
}
.text-layer {
  position: absolute; top: 0; left: 0; overflow: hidden; opacity: 0.2; line-height: 1;
}
.text-layer span { color: transparent; position: absolute; white-space: pre; cursor: text; }
.text-layer span.hl { background: rgba(250, 204, 21, 0.55); color: transparent; }

.floating-page-indicator {
  position: absolute; bottom: 18px; left: 50%; transform: translateX(-50%);
  background: rgba(15, 23, 42, 0.85); color: #fff; font-size: 0.78rem; font-weight: 600;
  padding: 6px 14px; border-radius: 999px; z-index: 30; pointer-events: none;
  opacity: 0; transition: opacity 0.25s ease;
}
.floating-page-indicator.visible { opacity: 1; }

.reader-loading, .reader-error {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); color: #fff; text-align: center; z-index: 20;
}
.spinner {
  width: 42px; height: 42px; border: 4px solid rgba(255,255,255,0.2); border-top-color: #fff;
  border-radius: 50%; animation: spin 0.8s linear infinite; margin: 0 auto 14px;
}
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 720px) {
  .reader-toolbar { justify-content: center; }
  .rt-search-box input { width: 90px; }
  .reader-toolbar .rt-title { display: none; }
}

