/* ============================================================
   HiDA Digital Library — Stylesheet
   Palette: Deep navy #0f1923 / Teal accent #1a6b5a / Warm cream text
   Typography: Playfair Display (headings) + DM Sans (body)
   ============================================================ */

:root {
  --navy:        #2e0639;
  --navy-2:      #2e0639;
  --navy-3:      #321839;
  --navy-4:      #2e0639;
  --teal:        #ad5207;
  --teal-dark:   #813c03;
  --teal-light:  #e8f5f1;
  --teal-mid:    #c8e6df;
  --gold:        #c9a84c;
  --text:        #1c2b24;
  --text-muted:  #6b7c74;
  --text-light:  #9ab0a8;
  --bg:          #f5f2ec;
  --bg-card:     #ffffff;
  --border:      #e0dbd0;
  --border-dark: #c8c0b0;
  --danger:      #c0392b;
  --success:     #ad5207;
  --hero-start:  #2e0639;
  --hero-mid:    #57086d;
  --hero-end:    #2e0639;
  --radius:      10px;
  --radius-lg:   16px;
  --shadow-sm:   0 1px 4px rgba(0,0,0,.06);
  --shadow:      0 2px 16px rgba(0,0,0,.08);
  --shadow-lg:   0 8px 40px rgba(0,0,0,.14);
  --font-display:'Playfair Display', Georgia, 'Times New Roman', serif;
  --font-body:   'DM Sans', 'Segoe UI', system-ui, sans-serif;
  --navbar-h:    64px;
}

/* ---------- Reset ---------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  font-size: 15px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--teal); text-decoration: none; transition: color .15s; }
a:hover { color: var(--teal-dark); }
img { max-width: 100%; display: block; }
button, input, select, textarea { font-family: var(--font-body); }

/* ---------- Navbar ---------- */
.navbar {
  background: var(--navy);
  height: var(--navbar-h);
  position: sticky;
  top: 0;
  z-index: 200;
  box-shadow: 0 2px 20px rgba(0,0,0,.3);
}
.navbar-inner {
  max-width: 1300px;
  margin: 0 auto;
  height: 100%;
  display: flex;
  align-items: center;
  padding: 0 2rem;
  gap: 2rem;
}

.navbar-center-links {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .3rem;
}
.navbar-center-links a {
  color: #fff;
  font-size: .88rem;
  font-weight: 400;
  padding: .4rem .9rem;
  border-radius: 6px;
  transition: color .15s, background .15s;
  white-space: nowrap;
}
.navbar-center-links a:hover, .navbar-center-links a.active { color: #fff; background: var(--navy-3); }

.navbar-auth {
  display: flex;
  align-items: center;
  gap: .7rem;
  flex-shrink: 0;
}
.navbar-auth a[href*="admin"] {
  color: #fff;
  font-size: .88rem;
  padding: .4rem .8rem;
  border-radius: 6px;
  background: var(--navy-3);
  white-space: nowrap;
}
.navbar-auth .nav-user {
  display: flex;
  align-items: center;
  gap: .6rem;
}
.navbar-auth .nav-user a { color: #5a7870; font-size: .82rem; }

.navbar-brand {
  display: flex;
  align-items: center;
  gap: .6rem;
  color: #fff;
  font-family: var(--font-display);
  font-size: 1.15rem;
  font-weight: 700;
  flex-shrink: 0;
  letter-spacing: .01em;
}
.navbar-brand:hover { color: var(--teal-mid); }
.brand-abbr {
  background: var(--teal);
  color: #fff;
  font-family: var(--font-display);
  font-size: .9rem;
  font-weight: 700;
  padding: .2rem .5rem;
  border-radius: 5px;
  letter-spacing: .04em;
}
.brand-text { color: #e0eeea; }

.navbar-search {
  flex: 1;
  max-width: 380px;
  position: relative;
}
.navbar-search input {
  width: 100%;
  background: var(--navy-3);
  border: 1px solid var(--navy-4);
  color: #e0eeea;
  padding: .5rem 1rem .5rem 2.4rem;
  border-radius: 20px;
  font-size: .88rem;
  transition: border-color .2s, background .2s;
}
.navbar-search input::placeholder { color: #5a7870; }
.navbar-search input:focus { outline: none; border-color: var(--teal); background: var(--navy-2); }

/* ── Search Autocomplete Suggestions (shared across all search bars) ── */
.search-suggest-dropdown {
  display: none;
  background: var(--bg-card, #fff);
  border: 1px solid var(--border, #e0dbd0);
  border-radius: 10px;
  box-shadow: 0 12px 32px rgba(0,0,0,.16);
  z-index: 9999;
}
.search-suggest-dropdown.open { display: block; }
.search-suggest-item {
  display: flex;
  align-items: center;
  gap: .7rem;
  padding: .6rem .9rem;
  cursor: pointer;
  text-decoration: none;
  color: var(--text, #1c2b24);
  border-bottom: 1px solid var(--border, #f0ede6);
  transition: background .12s;
}
.search-suggest-item:last-child { border-bottom: none; }
.search-suggest-item:hover, .search-suggest-item.active-suggest {
  background: var(--teal-light, #e8f5f1);
}
.search-suggest-thumb {
  width: 34px; height: 34px; border-radius: 6px; flex-shrink: 0;
  object-fit: cover; background: var(--navy, #0f1923);
  display: flex; align-items: center; justify-content: center; font-size: 1rem;
}
.search-suggest-text { min-width: 0; flex: 1; }
.search-suggest-title {
  font-size: .86rem; font-weight: 600; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
}
.search-suggest-creator {
  font-size: .74rem; color: var(--text-muted, #6b7c74);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.search-suggest-empty {
  padding: .9rem 1rem; font-size: .82rem; color: var(--text-muted, #6b7c74); text-align: center;
}
.search-suggest-loading {
  padding: .7rem 1rem; font-size: .8rem; color: var(--text-muted, #6b7c74); text-align: center;
}

.navbar-search .search-icon {
  position: absolute;
  left: .85rem;
  top: 50%;
  transform: translateY(-50%);
  color: #5a7870;
  font-size: .9rem;
  pointer-events: none;
}

.navbar-nav {
  display: none;
  align-items: center;
  gap: .2rem;
  margin-left: auto;
}
.navbar-nav a {
  color: #fff;
  font-size: .88rem;
  font-weight: 400;
  padding: .4rem .8rem;
  border-radius: 6px;
  transition: color .15s, background .15s;
  white-space: nowrap;
}
.navbar-nav a:hover, .navbar-nav a.active { color: #fff; background: var(--navy-3); }

.nav-divider { width: 1px; height: 20px; background: var(--navy-4); margin: 0 .4rem; }

.btn-nav-signin {
  background: var(--teal) !important;
  color: #fff !important;
  padding: .4rem 1rem !important;
  border-radius: 20px !important;
  font-weight: 500 !important;
}
.btn-nav-signin:hover { background: var(--teal-dark) !important; }

.nav-user {
  display: flex;
  align-items: center;
  gap: .6rem;
}
.nav-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--teal);
  color: #fff;
  font-size: .75rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

/* ---------- Page wrapper ---------- */
.page-wrap {
  flex: 1;
  max-width: 1300px;
  margin: 0 auto;
  width: 100%;
  padding: 2.5rem 1.5rem;
}
.page-wrap.full { max-width: 100%; padding: 0; }

/* ---------- Flash messages ---------- */
.flash {
  padding: .85rem 1.2rem;
  border-radius: var(--radius);
  margin-bottom: 1.5rem;
  font-size: .9rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: .6rem;
}
.flash-success { background: #d4f4e8; color: #0d5c3a; border-left: 4px solid var(--teal); }
.flash-error   { background: #fde8e8; color: #7b1c1c; border-left: 4px solid var(--danger); }

/* ---------- Hero ---------- */
.hero {
  background: linear-gradient(135deg, #2e0639 0%, #57086d 50%, #2e0639 100%);
  color: #fff;
  padding: 4.5rem 2rem;
  text-align: center;
  position: relative;
  overflow: hidden;
}
.hero::before {
  content: '';
  position: absolute;
  inset: 0;
  background: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%231a6b5a' fill-opacity='0.04'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
  pointer-events: none;
}
.hero-badge {
  display: none; /* temporary */
  /*display: inline-flex;*/
  align-items: center;
  gap: .4rem;
  background: rgba(26,107,90,.3);
  border: 1px solid rgba(26,107,90,.5);
  color: var(--teal-mid);
  font-size: .78rem;
  font-weight: 600;
  padding: .3rem .9rem;
  border-radius: 20px;
  margin-bottom: 1.5rem;
  letter-spacing: .06em;
  text-transform: uppercase;
}
.hero h1 {
  font-family: var(--font-display);
  font-size: clamp(2rem, 5vw, 3.2rem);
  font-weight: 700;
  line-height: 1.2;
  margin-bottom: 1rem;
  color: #fff;
}
.hero h1 em { color: var(--teal-mid); font-style: normal; }
.hero p {
  color: #c8e6df;
  font-size: 1.2rem;
  max-width: 620px;
  margin: 0 auto 2rem;
  line-height: 1.6;
}
.hero-search {
  display: flex;
  max-width: 540px;
  margin: 0 auto 1.5rem;
  background: #fff;
  border-radius: 50px;
  overflow: hidden;
  box-shadow: 0 4px 30px rgba(0,0,0,.2);
}
.hero-search input {
  flex: 1;
  border: none;
  padding: .9rem 1.4rem;
  font-size: .95rem;
  color: var(--text);
  background: transparent;
}
.hero-search input:focus { outline: none; }
.hero-search button {
  background: var(--teal);
  color: #fff;
  border: none;
  padding: .9rem 1.6rem;
  font-size: .9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .2s;
}
.hero-search button:hover { background: var(--teal-dark); }
.hero-tags { color: #5a7870; font-size: .82rem; }
.hero-tags a { color: #8fb8b0; font-weight: 500; margin: 0 .2rem; }
.hero-tags a:hover { color: #fff; }

/* ---------- Stats bar (standalone section below hero) ---------- */
.stats-bar {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
}
.stats-bar-inner {
  max-width: 1300px;
  margin: 0 auto;
  padding: 2.2rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 3rem;
  flex-wrap: wrap;
}
.stats-bar-stat { text-align: center; }
.stats-bar-num {
  /*font-family: var(--font-display);*/
  font-size: 2.1rem;
  font-weight: 700;
  color: var(--teal);
  line-height: 1;
}
.stats-bar-label {
  font-size: .78rem;
  color: var(--text-muted);
  margin-top: .35rem;
  text-transform: uppercase;
  letter-spacing: .07em;
  font-weight: 600;
}
.stats-bar-divider {
  width: 1px;
  height: 40px;
  background: var(--border);
}

.hero-stats {
  display: flex;
  justify-content: center;
  gap: 3rem;
  margin-top: 3rem;
  flex-wrap: wrap;
}
.hero-stat { text-align: center; }
.hero-stat-num {
  font-family: var(--font-display);
  font-size: 2rem;
  font-weight: 700;
  color: #fff;
  line-height: 1;
}
.hero-stat-label { font-size: .78rem; color: #5a7870; margin-top: .3rem; text-transform: uppercase; letter-spacing: .06em; }

/* ---------- Section headings ---------- */
.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 1.5rem;
  gap: 1rem;
}
.section-label {
  font-size: .72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .12em;
  color: var(--teal);
  margin-bottom: .3rem;
}
.section-title {
  font-family: var(--font-display);
  font-size: 1.55rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1.2;
}
.section-link {
  font-size: .85rem;
  font-weight: 500;
  color: var(--teal);
  white-space: nowrap;
  flex-shrink: 0;
}
.section-link:hover { color: var(--teal-dark); }

/* ---------- Resource cards (new design) ---------- */
.books-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1.8rem;
}
.search-results-grid {
  grid-template-columns: repeat(3, 1fr);
}
@media (max-width: 900px) {
  .search-results-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 600px) {
  .search-results-grid { grid-template-columns: 1fr; }
}

.resource-card {
  background: var(--bg-card);
  border: 1.5px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: transform .22s cubic-bezier(.2,.8,.2,1), box-shadow .22s, border-color .22s;
  box-shadow: 0 2px 8px rgba(0,0,0,.06);
}
.resource-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 12px 36px rgba(0,0,0,.13);
  border-color: var(--teal-mid);
}

/* Thumbnail */
.resource-card-thumb {
  display: block;
  position: relative;
  aspect-ratio: 4 / 3;
  overflow: hidden;
  background: linear-gradient(135deg, var(--navy) 0%, #1a3028 100%);
  flex-shrink: 0;
}
.resource-card-thumb img {
  width: 100%; height: 100%;
  object-fit: cover;
  transition: transform .35s;
}
.resource-card:hover .resource-card-thumb img { transform: scale(1.04); }

.resource-thumb-placeholder {
  width: 100%; height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: .6rem;
  background: linear-gradient(145deg, #0f1923 0%, #1a3028 60%, #243444 100%);
}
.thumb-icon    { font-size: 2.4rem; opacity: .4; }
.thumb-initials {
  font-family: var(--font-display);
  font-size: 2rem;
  font-weight: 700;
  color: rgba(200,230,220,.45);
  letter-spacing: .08em;
  text-transform: uppercase;
}

/* Badges on thumbnail */
.resource-type-badge {
  position: absolute;
  top: 8px; left: 8px;
  font-size: .68rem;
  font-weight: 700;
  padding: .2rem .55rem;
  border-radius: 20px;
  display: inline-flex;
  align-items: center;
  gap: .25rem;
  backdrop-filter: blur(4px);
  box-shadow: 0 1px 4px rgba(0,0,0,.15);
}
.resource-lang-badge {
  position: absolute;
  top: 8px; right: 8px;
  background: rgba(0,0,0,.45);
  color: #fff;
  font-size: .65rem;
  font-weight: 700;
  padding: .18rem .45rem;
  border-radius: 4px;
  letter-spacing: .06em;
  backdrop-filter: blur(4px);
}
.resource-free-badge {
  /*position: absolute;*/
  display: none; /* temporary */
  bottom: 8px; left: 8px;
  background: #22c55e;
  color: #fff;
  font-size: .62rem;
  font-weight: 700;
  padding: .15rem .45rem;
  border-radius: 4px;
  letter-spacing: .04em;
  text-transform: uppercase;
}

/* Card body */
.resource-card-body {
  padding: 1rem 1.1rem;
  display: flex;
  flex-direction: column;
  gap: .35rem;
  flex: 1;
}
.resource-title {
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1.3;
  text-decoration: none;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.resource-title:hover { color: var(--teal); }
.resource-creator {
  font-size: .82rem;
  color: var(--text-muted);
  font-weight: 500;
}
.resource-desc {
  font-size: .8rem;
  color: var(--text-muted);
  line-height: 1.55;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin-top: .15rem;
}
.resource-tags {
  display: flex;
  flex-wrap: wrap;
  gap: .3rem;
  margin-top: .2rem;
}
.resource-tag {
  background: var(--bg);
  color: var(--text-muted);
  font-size: .68rem;
  padding: .15rem .5rem;
  border-radius: 20px;
  border: 1px solid var(--border);
  text-decoration: none;
  transition: all .15s;
}
.resource-tag:hover { background: var(--teal-light); color: var(--teal); border-color: var(--teal-mid); }

/* Card footer */
.resource-card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .5rem;
  margin-top: auto;
  padding: .7rem 1.1rem .9rem;
  border-top: 1px solid var(--border);
  background: #fafaf8;
}
.resource-pub {
  font-size: .74rem;
  color: var(--text-light);
  display: flex;
  flex-direction: column;
  gap: .05rem;
  min-width: 0;
  overflow: hidden;
}
.resource-hosted { color: var(--text-light); font-size: .7rem; }
.resource-open-btn {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  background: var(--teal);
  color: #fff;
  font-size: .8rem;
  font-weight: 600;
  padding: .38rem .95rem;
  border-radius: 7px;
  text-decoration: none;
  white-space: nowrap;
  flex-shrink: 0;
  transition: background .15s, transform .1s;
  box-shadow: 0 2px 6px rgba(26,107,90,.25);
}
.resource-open-btn:hover { background: var(--teal-dark); color: #fff; transform: translateY(-1px); }

/* Legacy compatibility */
.book-card { display: block; color: inherit; }
.book-cover-wrap { aspect-ratio: 2/3; overflow: hidden; background: var(--navy); position: relative; }
.book-cover-wrap img { width:100%;height:100%;object-fit:cover; }
.book-cover-placeholder { width:100%;height:100%;display:flex;flex-direction:column;align-items:center;justify-content:center;padding:1rem;gap:.5rem; }
.cover-icon { font-size:2.5rem;opacity:.4; }
.cover-title-text { font-family:var(--font-display);font-size:.75rem;color:var(--teal-mid);text-align:center;line-height:1.3; }
.cover-author-text { font-size:.68rem;color:#4a6a62;text-align:center; }
.book-info { padding:.8rem; }
.book-title { font-family:var(--font-display);font-size:.88rem;font-weight:600;line-height:1.3;color:var(--text); }
.book-author { font-size:.75rem;color:var(--text-muted); }
.book-cat-badge { display:inline-block;background:var(--teal-light);color:var(--teal);font-size:.65rem;font-weight:700;padding:.12rem .5rem;border-radius:20px; }

/* ---------- Categories grid ---------- */
.cats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1rem;
}
.cat-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .9rem 1.1rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: all .2s;
  color: var(--text);
}
.cat-card:hover {
  background: var(--teal-light);
  border-color: var(--teal-mid);
  color: var(--teal-dark);
  transform: translateX(3px);
}
.cat-name { font-weight: 500; font-size: .9rem; }
.cat-count { font-size: .78rem; color: var(--text-muted); }
.cat-card:hover .cat-count { color: var(--teal); }

/* ---------- Categories page list ---------- */
.cats-list { display: flex; flex-direction: column; gap: 0; }
.cat-row {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  padding: 1rem 1.4rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  margin-bottom: -1px;
  text-decoration: none;
  color: var(--text);
  transition: background .15s, color .15s;
}
.cat-row:first-child { border-radius: var(--radius) var(--radius) 0 0; }
.cat-row:last-child  { border-radius: 0 0 var(--radius) var(--radius); margin-bottom: 0; }
.cat-row:hover { background: var(--teal-light); color: var(--teal-dark); z-index: 1; position: relative; }
.cat-num { font-size: .8rem; color: var(--text-muted); font-weight: 600; width: 28px; text-align: right; }
.cat-row-name { flex: 1; font-weight: 500; }
.cat-row-count { font-size: .82rem; color: var(--text-muted); }

/* ---------- Featured book of the month ---------- */
.featured-month {
  display: grid;
  grid-template-columns: 180px 1fr;
  gap: 2rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 2rem;
  box-shadow: var(--shadow);
  align-items: start;
}
.featured-month .book-cover-wrap { border-radius: 10px; box-shadow: var(--shadow-lg); }
.featured-month-badge {
  display: inline-block;
  background: var(--teal);
  color: #fff;
  font-size: .7rem;
  font-weight: 700;
  padding: .2rem .7rem;
  border-radius: 20px;
  text-transform: uppercase;
  letter-spacing: .08em;
  margin-bottom: .8rem;
}
.featured-month h3 {
  font-family: var(--font-display);
  font-size: 1.5rem;
  font-weight: 700;
  line-height: 1.2;
  margin-bottom: .4rem;
}
.featured-month .by { color: var(--text-muted); font-size: .9rem; margin-bottom: 1rem; }
.featured-month p   { font-size: .92rem; color: var(--text-muted); line-height: 1.6; margin-bottom: 1.5rem; }

/* ---------- Faculty recs ---------- */
.faculty-list { list-style: none; display: flex; flex-direction: column; gap: 0; }
.faculty-item {
  display: flex;
  gap: 1rem;
  align-items: center;
  padding: .8rem 0;
  border-bottom: 1px solid var(--border);
  text-decoration: none;
  color: var(--text);
  transition: color .15s;
}
.faculty-item:last-child { border-bottom: none; }
.faculty-item:hover { color: var(--teal); }
.faculty-item-cat {
  font-size: .7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--teal);
  flex-shrink: 0;
  width: 120px;
}
.faculty-item-title { flex: 1; font-weight: 500; font-size: .9rem; }
.faculty-item-author { font-size: .8rem; color: var(--text-muted); }

/* ---------- Browse page layout ---------- */
.browse-layout {
  display: grid;
  grid-template-columns: 240px 1fr;
  gap: 2rem;
  align-items: start;
}
.browse-sidebar {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  position: sticky;
  top: calc(var(--navbar-h) + 1.5rem);
}
.sidebar-title {
  background: var(--navy);
  color: #c8d8d4;
  padding: .85rem 1.2rem;
  font-size: .75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .1em;
}
.sidebar-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: .65rem 1.2rem;
  font-size: .88rem;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background .15s;
  color: var(--text);
  text-decoration: none;
}
.sidebar-item:last-child { border-bottom: none; }
.sidebar-item:hover, .sidebar-item.active {
  background: var(--teal-light);
  color: var(--teal-dark);
}
.sidebar-item .count { font-size: .75rem; color: var(--text-muted); }
.sidebar-item.active .count { color: var(--teal); }

.browse-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.3rem;
  gap: 1rem;
  flex-wrap: wrap;
}
.browse-count { font-size: .88rem; color: var(--text-muted); }
.sort-select {
  display: flex;
  align-items: center;
  gap: .5rem;
  font-size: .85rem;
  color: var(--text-muted);
}
.sort-select select {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: .3rem .7rem;
  font-size: .85rem;
  background: var(--bg-card);
  color: var(--text);
  cursor: pointer;
}
.sort-select select:focus { outline: none; border-color: var(--teal); }

/* ---------- Book detail ---------- */
.book-detail-layout {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 2.5rem;
  align-items: start;
}
.book-detail-cover {
  border-radius: 12px;
  overflow: hidden;
  box-shadow: var(--shadow-lg);
  position: sticky;
  top: calc(var(--navbar-h) + 1.5rem);
}
.book-detail-cover .book-cover-wrap { aspect-ratio: 2/3; }

.breadcrumb {
  display: flex;
  align-items: center;
  gap: .4rem;
  font-size: .82rem;
  color: var(--text-muted);
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}
.breadcrumb a { color: var(--text-muted); }
.breadcrumb a:hover { color: var(--teal); }
.breadcrumb .sep { color: var(--border-dark); }

.book-detail-cat {
  display: inline-block;
  background: var(--teal-light);
  color: var(--teal);
  font-size: .72rem;
  font-weight: 700;
  padding: .2rem .7rem;
  border-radius: 20px;
  text-transform: uppercase;
  letter-spacing: .06em;
  margin-bottom: .8rem;
}
.book-detail-title {
  font-family: var(--font-display);
  font-size: 2rem;
  font-weight: 700;
  line-height: 1.2;
  margin-bottom: .5rem;
}
.book-detail-author { font-size: 1rem; color: var(--text-muted); margin-bottom: 1.5rem; }

.book-meta-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: .6rem;
  margin-bottom: 1.5rem;
}
.meta-item { background: var(--bg); border-radius: 8px; padding: .6rem .8rem; }
.meta-label { font-size: .7rem; font-weight: 700; text-transform: uppercase; letter-spacing: .07em; color: var(--text-muted); margin-bottom: .15rem; }
.meta-value { font-size: .88rem; font-weight: 500; color: var(--text); }

.read-action {
  display: inline-flex;
  align-items: center;
  gap: .5rem;
  background: var(--teal);
  color: #fff;
  padding: .8rem 2rem;
  border-radius: 8px;
  font-weight: 600;
  font-size: .95rem;
  margin-bottom: .5rem;
  transition: background .2s;
}
.read-action:hover { background: var(--teal-dark); color: #fff; }
.read-note { font-size: .78rem; color: var(--text-muted); display: flex; align-items: center; gap: .3rem; }

.action-row { display: flex; align-items: center; gap: .8rem; margin-bottom: 2rem; flex-wrap: wrap; }
.btn-action {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  padding: .5rem 1.1rem;
  border-radius: 8px;
  font-size: .85rem;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  transition: all .15s;
}
.btn-action:hover { background: var(--teal-light); border-color: var(--teal-mid); color: var(--teal-dark); }
.btn-action.active { background: var(--teal-light); border-color: var(--teal); color: var(--teal); }

.book-description { font-size: .95rem; line-height: 1.7; color: var(--text-muted); margin-bottom: 2rem; }

.toc-list { list-style: none; }
.toc-item {
  display: flex;
  align-items: center;
  gap: .8rem;
  padding: .55rem 0;
  border-bottom: 1px solid var(--border);
  font-size: .9rem;
  color: var(--text-muted);
}
.toc-item:last-child { border-bottom: none; }
.toc-num { font-size: .75rem; color: var(--text-light); width: 24px; text-align: right; flex-shrink: 0; }

.tags-row { display: flex; gap: .5rem; flex-wrap: wrap; margin-top: .5rem; }
.tag {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: .78rem;
  padding: .25rem .7rem;
  border-radius: 20px;
  transition: all .15s;
}
.tag:hover { background: var(--teal-light); border-color: var(--teal-mid); color: var(--teal); }

/* ---------- Reader ---------- */
body.reader-body { overflow: hidden; }
.reader-shell {
  height: calc(100vh - var(--navbar-h));
  display: flex;
  flex-direction: column;
}
.reader-bar {
  background: var(--navy-2);
  border-bottom: 1px solid var(--navy-4);
  padding: .6rem 1.2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-shrink: 0;
}
.reader-book-info .title { font-weight: 600; color: #e0eeea; font-size: .92rem; }
.reader-book-info .author { font-size: .75rem; color: #5a7870; }
.reader-book-info .badge { display: inline-block; background: rgba(26,107,90,.25); color: var(--teal-mid); font-size: .68rem; font-weight: 700; padding: .1rem .5rem; border-radius: 10px; margin-right: .4rem; }
.reader-actions { display: flex; align-items: center; gap: .6rem; }
.reader-note { font-size: .75rem; color: #4a6860; }
#pdf-frame { flex: 1; border: none; width: 100%; display: block; background: #2c3040; }

/* ---------- Dashboard ---------- */
.dashboard-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2rem;
}
.dash-hero {
  grid-column: 1 / -1;
  background: var(--navy);
  border-radius: var(--radius-lg);
  padding: 2rem 2.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 2rem;
  flex-wrap: wrap;
}
.dash-hero-left h2 {
  font-family: var(--font-display);
  font-size: 1.7rem;
  color: #fff;
  margin-bottom: .2rem;
}
.dash-hero-left .subtitle { color: #6b8a84; font-size: .9rem; }
.dash-stats { display: flex; gap: 2rem; }
.dash-stat { text-align: center; }
.dash-stat-num { font-family: var(--font-display); font-size: 1.8rem; color: #fff; font-weight: 700; line-height: 1; }
.dash-stat-label { font-size: .72rem; color: #5a7870; text-transform: uppercase; letter-spacing: .06em; margin-top: .2rem; }

.dash-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}
.dash-card-head {
  padding: 1rem 1.4rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.dash-card-title { font-weight: 600; font-size: .9rem; }
.dash-card-body { padding: 1.2rem 1.4rem; }

.progress-book {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: .7rem 0;
  border-bottom: 1px solid var(--border);
  text-decoration: none;
  color: var(--text);
  transition: color .15s;
}
.progress-book:last-child { border-bottom: none; }
.progress-book:hover { color: var(--teal); }
.progress-info { flex: 1; min-width: 0; }
.progress-title { font-weight: 500; font-size: .9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.progress-cat   { font-size: .75rem; color: var(--text-muted); margin-bottom: .4rem; }
.progress-bar-wrap { background: var(--bg); border-radius: 20px; height: 5px; overflow: hidden; }
.progress-bar { height: 100%; background: var(--teal); border-radius: 20px; transition: width .4s; }
.progress-pct { font-size: .75rem; color: var(--teal); font-weight: 600; flex-shrink: 0; }

.notif-item {
  display: flex;
  gap: .8rem;
  align-items: flex-start;
  padding: .75rem 0;
  border-bottom: 1px solid var(--border);
  font-size: .88rem;
}
.notif-item:last-child { border-bottom: none; }
.notif-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--teal); flex-shrink: 0; margin-top: .45rem; }
.notif-text { flex: 1; }
.notif-title { font-weight: 500; margin-bottom: .1rem; }
.notif-sub   { color: var(--text-muted); font-size: .8rem; }
.notif-time  { font-size: .75rem; color: var(--text-light); flex-shrink: 0; }

/* ---------- Advanced search ---------- */
.search-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 2.5rem;
  box-shadow: var(--shadow);
  margin-bottom: 2rem;
}
.search-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1.2rem;
  margin-bottom: 1.5rem;
}
.form-group label {
  display: block;
  font-size: .75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--text-muted);
  margin-bottom: .4rem;
}
.form-group input, .form-group select {
  width: 100%;
  padding: .65rem .9rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  font-size: .9rem;
  color: var(--text);
  transition: border-color .2s;
}
.form-group input:focus, .form-group select:focus {
  outline: none; border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(26,107,90,.1);
}

/* ---------- Auth ---------- */
.auth-wrap { max-width: 440px; margin: 3rem auto; }
.auth-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 2.5rem;
  box-shadow: var(--shadow);
}
.auth-logo { text-align: center; margin-bottom: 2rem; }
.auth-logo .abbr {
  display: inline-block;
  background: var(--navy);
  color: #fff;
  font-family: var(--font-display);
  font-size: 1.5rem;
  font-weight: 700;
  width: 90px; height: 56px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto .8rem;
}
.auth-card h2 { font-family: var(--font-display); font-size: 1.6rem; margin-bottom: .3rem; text-align: center; }
.auth-subtitle { text-align: center; color: var(--text-muted); font-size: .88rem; margin-bottom: 2rem; }
.form-footer { text-align: center; margin-top: 1.2rem; font-size: .88rem; color: var(--text-muted); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .45rem;
  padding: .6rem 1.4rem;
  border-radius: 8px;
  font-size: .9rem;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: all .2s;
  text-decoration: none;
  line-height: 1;
  white-space: nowrap;
}
.btn-primary   { background: var(--teal); color: #fff; }
.btn-primary:hover { background: var(--teal-dark); color: #fff; }
.btn-secondary { background: var(--bg); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--border); }
.btn-danger    { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #a93226; color: #fff; }
.btn-ghost     { background: transparent; color: var(--text-muted); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--bg); }
.btn-sm { padding: .35rem .85rem; font-size: .82rem; border-radius: 6px; }
.btn-lg { padding: .8rem 2rem; font-size: 1rem; border-radius: 10px; }
.btn-full { width: 100%; }

/* ---------- Pagination ---------- */
.pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: .3rem;
  margin-top: 3rem;
  flex-wrap: wrap;
}
.page-btn {
  min-width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  font-size: .88rem;
  border: 1px solid var(--border);
  color: var(--text);
  transition: all .15s;
  padding: 0 .5rem;
  text-decoration: none;
}
.page-btn:hover { background: var(--teal); color: #fff; border-color: var(--teal); }
.page-btn.active { background: var(--teal); color: #fff; border-color: var(--teal); font-weight: 600; }
.page-btn.disabled { opacity: .35; pointer-events: none; }

/* ---------- Admin layout ---------- */
.admin-wrap {
  display: flex;
  min-height: calc(100vh - var(--navbar-h));
}
.admin-sidebar {
  width: 240px;
  flex-shrink: 0;
  background: var(--navy);
  display: flex;
  flex-direction: column;
  padding: 1.5rem 0;
}
.admin-sidebar-logo {
  padding: 0 1.4rem 1.5rem;
  border-bottom: 1px solid var(--navy-3);
  margin-bottom: 1rem;
  font-family: var(--font-display);
  font-size: .95rem;
  color: #9ab8b0;
  font-weight: 600;
}
.admin-nav-label {
  font-size: .68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .12em;
  color: #3a5a52;
  padding: .5rem 1.4rem .3rem;
}
.admin-nav-item {
  display: flex;
  align-items: center;
  gap: .7rem;
  padding: .65rem 1.4rem;
  color: #8fb8b0;
  font-size: .88rem;
  font-weight: 400;
  transition: all .15s;
  text-decoration: none;
  border-left: 3px solid transparent;
}
.admin-nav-item:hover { background: var(--navy-2); color: #c8e6df; }
.admin-nav-item.active { background: var(--navy-2); color: #fff; border-left-color: var(--teal); }
.admin-nav-icon { width: 18px; text-align: center; font-size: .9rem; }

.admin-main { flex: 1; padding: 2rem; overflow-x: auto; background: var(--bg); }
.admin-page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.8rem;
  gap: 1rem;
  flex-wrap: wrap;
}
.admin-page-head h1 {
  font-family: var(--font-display);
  font-size: 1.6rem;
  font-weight: 700;
}

/* ---------- Stat cards ---------- */
.stat-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 1.2rem;
  margin-bottom: 2rem;
}
.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.3rem 1.5rem;
  box-shadow: var(--shadow-sm);
}
.stat-card-num  { font-family: var(--font-display); font-size: 2.2rem; font-weight: 700; color: var(--teal); line-height: 1; }
.stat-card-label{ font-size: .82rem; color: var(--text-muted); margin-top: .3rem; }

/* ---------- Tables ---------- */
.data-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--bg-card);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.data-table th {
  background: var(--navy);
  color: #8fb8b0;
  font-size: .72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  padding: .85rem 1rem;
  text-align: left;
  white-space: nowrap;
}
.data-table td {
  padding: .7rem 1rem;
  border-bottom: 1px solid var(--border);
  font-size: .88rem;
  vertical-align: middle;
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: #f9f7f3; }

/* ---------- Badges ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  padding: .18rem .6rem;
  border-radius: 20px;
  font-size: .7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.badge-admin   { background: #fef3c7; color: #92400e; }
.badge-manager { background: #ddd6fe; color: #5b21b6; }
.badge-editor  { background: #e0e7ff; color: #3730a3; }
.badge-user    { background: var(--teal-light); color: var(--teal-dark); }
.badge-active  { background: #d1fae5; color: #065f46; }
.badge-inactive{ background: #fee2e2; color: #991b1b; }
.badge-featured{ background: #fef3c7; color: #92400e; }

/* ---------- Forms ---------- */
.form-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 2rem;
  box-shadow: var(--shadow-sm);
}
.form-section-title {
  font-weight: 600;
  font-size: .88rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .08em;
  margin-bottom: 1rem;
  margin-top: 1.5rem;
  border-bottom: 1px solid var(--border);
  padding-bottom: .5rem;
}
.form-section-title:first-child { margin-top: 0; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 1rem; }
.form-group textarea {
  width: 100%;
  padding: .65rem .9rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  font-size: .9rem;
  color: var(--text);
  min-height: 110px;
  resize: vertical;
  transition: border-color .2s;
}
.form-group textarea:focus { outline: none; border-color: var(--teal); box-shadow: 0 0 0 3px rgba(26,107,90,.1); }
.form-hint { font-size: .75rem; color: var(--text-light); margin-top: .3rem; }

/* ---------- Upload area ---------- */
.upload-area {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 2rem;
  text-align: center;
  transition: border-color .2s, background .2s;
  cursor: pointer;
  position: relative;
}
.upload-area:hover, .upload-area.drag-over {
  border-color: var(--teal);
  background: var(--teal-light);
}
.upload-area input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
  width: 100%;
  height: 100%;
}
.upload-icon { font-size: 2rem; margin-bottom: .5rem; opacity: .5; }
.upload-text { font-size: .88rem; color: var(--text-muted); }
.upload-hint { font-size: .75rem; color: var(--text-light); margin-top: .3rem; }

/* ---------- Footer ---------- */
.site-footer {
  background: var(--navy);
  color: #4a6a62;
  padding: 3.5rem 2rem 2rem;
  margin-top: auto;
}
.footer-grid {
  max-width: 1300px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 2fr 1fr 1fr 1fr;
  gap: 2rem;
  margin-bottom: 2.5rem;
}
.footer-brand { font-family: var(--font-display); font-size: 1.1rem; color: #fff; font-weight: 700; margin-bottom: .5rem; }
.footer-org { color: #fff; font-size: .82rem; line-height: 1.6; margin-bottom: 1rem; }
.footer-contact { font-size: .78rem; color: #fff; }
.footer-contact a { color: #fff; }
.footer-col-title {font-size: .80rem;font-weight: 800;text-transform: uppercase;letter-spacing: .1em;color: #ad5207;margin-bottom: .8rem;}
.footer-links { list-style: none; display: flex; flex-direction: column; gap: .4rem; }
.footer-links a {color: #fff;font-size: .85rem;transition: color .15s;}
.footer-links a:hover { color: #c8d8d4; }
.footer-bottom {
  max-width: 1300px;
  margin: 0 auto;
  border-top: 1px solid var(--navy-3);
  padding-top: 1.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: .8rem;
  gap: 1rem;
  flex-wrap: wrap;
}

/* ---------- Misc ---------- */
.empty-state {
  text-align: center;
  padding: 4rem 2rem;
  color: var(--text-muted);
}
.empty-state .icon { font-size: 3.5rem; margin-bottom: 1rem; opacity: .4; }
.empty-state h3 { font-family: var(--font-display); font-size: 1.2rem; margin-bottom: .4rem; color: var(--text); }

.divider { border: none; border-top: 1px solid var(--border); margin: 2rem 0; }

/* ==========
   MOBILE NAVIGATION — Hamburger menu + slide-out sidebar
   ========== */

/* Hamburger toggle button — hidden on desktop */
.navbar-toggle {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  width: 36px;
  height: 36px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 8px;
  flex-shrink: 0;
  z-index: 200;
}
.navbar-toggle span {
  display: block;
  width: 100%;
  height: 2px;
  background: #c8d8d4;
  border-radius: 2px;
  transition: transform .25s, opacity .25s;
}
.navbar-toggle.open span:nth-child(1) { transform: translateY(6px) rotate(45deg); }
.navbar-toggle.open span:nth-child(2) { opacity: 0; }
.navbar-toggle.open span:nth-child(3) { transform: translateY(-6px) rotate(-45deg); }

.navbar-search-mobile { display: none; }
.navbar-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,.4);
  z-index: 150;
}
.navbar-overlay.open { display: block; }

/* Admin sidebar toggle */
.admin-sidebar-toggle {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  width: 36px;
  height: 36px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 8px;
  margin-right: .6rem;
  flex-shrink: 0;
}
.admin-sidebar-toggle span {
  display: block;
  width: 100%;
  height: 2px;
  background: #c8d8d4;
  border-radius: 2px;
}
.admin-sidebar-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,.4);
  z-index: 90;
}
.admin-sidebar-overlay.open { display: block; }


/* ==========
   TABLET (≤1024px)
   ========== */
@media (max-width: 1024px) {
  .browse-layout { grid-template-columns: 200px 1fr; }
  .footer-grid { grid-template-columns: 1fr 1fr; }
  .book-detail-layout { grid-template-columns: 220px 1fr; gap: 1.5rem; }
  .books-grid { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 1.2rem; }

  /* Admin: 2-col grids become 1-col */
  .admin-page-head + div[style*="grid-template-columns:1fr 1fr"],
  div[style*="grid-template-columns: 1fr 1fr"] { grid-template-columns: 1fr !important; }
  form[style*="grid-template-columns:1fr 300px"],
  form[style*="grid-template-columns: 1fr 300px"] > div,
  div[style*="grid-template-columns:1fr 300px"] { grid-template-columns: 1fr !important; }
}


/* ==========
   MOBILE (≤768px)
   ========== */
@media (max-width: 768px) {

  /* ---------- Login/Register site name — shrink next to logo on mobile ---------- */
  .auth-site-name { font-size: 1.1rem !important; }

  /* ---------- Site Navbar ---------- */
  .navbar-inner {
    padding: 0 1rem;
    flex-wrap: nowrap;
    position: relative;
  }
  .navbar-search { display: none; }
  .navbar-center-links { display: none; }
  .navbar-auth { display: none; }
  .navbar-toggle { display: flex; }
  .navbar-nav {
    display: none;
    position: fixed;
    top: 0; right: 0;
    width: min(280px, 80vw);
    height: 100vh;
    background: var(--navy);
    flex-direction: column;
    align-items: stretch;
    padding: 4.5rem 1.2rem 1.5rem;
    gap: .3rem;
    overflow-y: auto;
    z-index: 160;
    box-shadow: -8px 0 24px rgba(0,0,0,.25);
    transform: translateX(100%);
    transition: transform .28s ease;
  }
  .navbar-nav.open { display: flex; transform: translateX(0); }
  .navbar-nav a {
    padding: .75rem .8rem;
    border-radius: 8px;
    width: 100%;
  }
  .navbar-search-mobile {
    display: flex;
    align-items: center;
    gap: .5rem;
    background: var(--navy-2);
    border-radius: 8px;
    padding: .5rem .8rem;
    margin-bottom: .8rem;
  }
  .navbar-search-mobile input {
    background: none; border: none; outline: none;
    color: #e8f2ee; font-size: .9rem; flex: 1; min-width: 0;
  }
  .navbar-search-mobile input::placeholder { color: #5a7870; }
  .nav-divider { margin: .8rem 0; border-top: 1px solid var(--navy-3); }

  /* Admin/Editor tab in mobile nav */
  .navbar-nav a[href*="admin"] {
    background: var(--navy-2);
    display: flex;
    align-items: center;
    gap: .5rem;
    font-weight: 600;
  }
  .navbar-nav a[href*="admin"]::before { content: "\2699"; font-size: .9rem; }

  /* User info card at bottom of mobile nav */
  .nav-user {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    background: var(--navy-2);
    border-radius: 10px;
    padding: .8rem 1rem;
    margin-top: .4rem;
    width: 100%;
  }
  .nav-user .nav-avatar { width: 38px; height: 38px; font-size: .82rem; }
  .nav-user a[href*="logout"] {
    background: rgba(192,112,112,.12);
    color: #e08a8a !important;
    padding: .4rem .8rem;
    border-radius: 8px;
    font-weight: 600;
  }

  .btn-nav-signin { width: 100%; text-align: center; margin-top: .5rem; padding: .7rem 1rem !important; }

  /* ---------- Hero / Homepage ---------- */
  .hero { padding: 2.5rem 1.2rem; }
  .stats-bar-inner { gap: 1.5rem; flex-wrap: wrap; justify-content: center; padding: 1.6rem 1.2rem; }
  .stats-bar-divider { display: none; }
  .hero h1 { font-size: 1.6rem !important; }

  /* ---------- Browse / Search layout ---------- */
  .browse-layout { grid-template-columns: 1fr; }
  .browse-sidebar { position: static; margin-bottom: 1rem; }
  .books-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: .9rem; }

  /* Homepage Featured/New Arrivals sections: 1 per row, larger card */
  .homepage-section .books-grid,
  section .books-grid {
    grid-template-columns: 1fr;
    gap: 1rem;
  }
  .homepage-section .resource-card,
  section .resource-card {
    display: grid;
    grid-template-columns: 110px 1fr;
    grid-template-rows: auto;
  }
  .homepage-section .resource-card-thumb,
  section .resource-card-thumb {
    aspect-ratio: auto;
    height: 100%;
  }
  .homepage-section .resource-card-footer,
  section .resource-card-footer {
    grid-column: 1 / -1;
  }
  .homepage-section .resource-card-body,
  section .resource-card-body {
    padding: .8rem .9rem;
  }

  /* ---------- Book detail page ---------- */
  .book-detail-layout { grid-template-columns: 1fr; gap: 1.2rem; }
  .book-detail-cover { position: static; max-width: 180px; margin: 0 auto; }
  .book-detail-title { font-size: 1.4rem !important; }
  .action-row { flex-wrap: wrap; }
  .action-row .btn-action { flex: 1; min-width: 100px; }

  /* ---------- Dashboard ---------- */
  .dashboard-grid { grid-template-columns: 1fr !important; }
  .dash-hero { flex-direction: column; align-items: flex-start; gap: 1rem; }
  .dash-stats { width: 100%; justify-content: space-between; }

  /* ---------- Homepage sections ---------- */
  .featured-month { grid-template-columns: 1fr; }
  .footer-grid { grid-template-columns: 1fr; gap: 1.5rem; }

  /* ---------- Generic 2-column grids (forms, admin panels) ---------- */
  div[style*="grid-template-columns:1fr 1fr"],
  div[style*="grid-template-columns: 1fr 1fr"],
  div[style*="grid-template-columns:1fr 300px"],
  div[style*="grid-template-columns: 1fr 300px"],
  div[style*="grid-template-columns:repeat(4"],
  div[style*="grid-template-columns: repeat(4"],
  div[style*="grid-template-columns:repeat(2"],
  div[style*="grid-template-columns: repeat(2"] {
    grid-template-columns: 1fr !important;
  }
  form[style*="grid-template-columns"] { grid-template-columns: 1fr !important; }

  .form-row, .form-row-3 { grid-template-columns: 1fr; }

  /* ---------- ADMIN PANEL ---------- */
  .admin-wrap { flex-direction: column; }
  .admin-sidebar {
    position: fixed;
    top: 0; left: 0;
    width: min(260px, 80vw);
    height: 100vh;
    z-index: 100;
    transform: translateX(-100%);
    transition: transform .25s ease;
    overflow-y: auto;
    box-shadow: 8px 0 24px rgba(0,0,0,.2);
  }
  .admin-sidebar.open { transform: translateX(0); }
  .admin-sidebar-toggle { display: flex; }
  .admin-main { padding: 1rem; width: 100%; }
  .admin-page-head { flex-direction: column; align-items: flex-start; gap: .7rem; }
  .admin-page-head h1 { font-size: 1.3rem; }

  /* Top admin header bar — hide/shrink non-essential items so it doesn't overflow */
  .navbar[style*="padding:0 2rem"] { padding: 0 .8rem !important; gap: .6rem !important; }
  .admin-brand-text { display: none; }
  .admin-view-site-link { display: none; }
  .admin-role-badge { display: none; }
  .admin-username-text { display: none; }
  .admin-signout-link { font-size: .78rem !important; white-space: nowrap; }
  .admin-nav-right { gap: .6rem !important; }
  .nav-user { gap: 0 !important; }

  /* Stat cards row wraps */
  .stat-cards { grid-template-columns: repeat(2, 1fr) !important; gap: .7rem; }
  .stat-card { padding: .8rem !important; }
  .stat-card-num { font-size: 1.3rem !important; }

  /* Filter bars / flag pills / any inline flex-wrap row of buttons — tighten spacing
     and let items wrap onto multiple lines cleanly instead of looking cramped */
  form[style*="display:flex"][style*="flex-wrap:wrap"],
  div[style*="display:flex"][style*="flex-wrap:wrap"] {
    gap: .4rem !important;
  }
  form[style*="display:flex"][style*="flex-wrap:wrap"] input[type="text"],
  form[style*="display:flex"][style*="flex-wrap:wrap"] input[type="date"],
  form[style*="display:flex"][style*="flex-wrap:wrap"] select {
    flex: 1 1 140px;
    min-width: 0;
  }

  /* Manage/View detail panels — force single column instead of squeezing side-by-side */
  div[style*="grid-template-columns:140px 1fr"],
  div[style*="grid-template-columns: 140px 1fr"] {
    grid-template-columns: 1fr !important;
  }
  div[style*="grid-template-columns:1fr 1fr"] > div:first-child img,
  div[style*="grid-template-columns: 1fr 1fr"] > div:first-child img {
    max-width: 160px;
    margin: 0 auto;
  }

  /* Action button rows (View/Edit/Delete etc.) — wrap and shrink instead of overflowing */
  .btn-sm { padding: .35rem .65rem !important; font-size: .78rem !important; }

  /* ---------- Tables: horizontal scroll wrapper ---------- */
  .data-table { font-size: .78rem; }
  .data-table th, .data-table td { padding: .5rem .4rem !important; white-space: nowrap; }
  div[style*="overflow-x:auto"], div[style*="overflow-x: auto"] {
    -webkit-overflow-scrolling: touch;
  }

  /* ---------- Analytics charts ---------- */
  div[style*="grid-template-columns:1fr 1fr 1fr"],
  div[style*="grid-template-columns: 1fr 1fr 1fr"] { grid-template-columns: 1fr !important; }

  /* ---------- Filter bars wrap nicely ---------- */
  form[style*="display:flex"] { flex-wrap: wrap; }

  /* ---------- Modals / citation box / upload areas ---------- */
  .upload-area { padding: 1.2rem .8rem; }

  /* ---------- Buttons stack on very small screens where side by side ---------- */
  .btn-full { width: 100%; }
}


/* ==========
   SMALL MOBILE (≤480px)
   ========== */
@media (max-width: 480px) {
  .books-grid {grid-template-columns: 1fr;gap: .7rem;}
  /*.books-grid { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: .7rem; }*/
  .stat-cards { grid-template-columns: repeat(2, 1fr) !important; }
  .navbar-brand .brand-text { display: none; }
  .hero h1 { font-size: 1.35rem !important; }
  .resource-card-body { padding: .75rem .85rem; }
  .resource-title { font-size: .9rem; }
  .form-card { padding: 1rem; }
  .data-table { font-size: .72rem; }
}


/* ==========
   READER PAGES (PDF / EPUB) — full-screen mobile adjustments
   ========== */
@media (max-width: 768px) {
  .reader-bar { padding: 0 .7rem; flex-wrap: wrap; height: auto; min-height: 52px; gap: .5rem; }
  .reader-title { font-size: .8rem; }
  .reader-cat { display: none; }
  .reader-note { display: none; }
  .btn-back { padding: .25rem .6rem; font-size: .76rem; }
  .epub-toolbar { flex-wrap: wrap; padding: .5rem .7rem; }
  #page-info { font-size: .76rem; min-width: 60px; }
}