:root {
  --primary-color: #111827;
  --secondary-color: #1f2937;
  --text-color: #f9fafb;
  --hover-color: #374151;
  --border-color: #4b5563;
  --transition-speed: 0.4s;
  --sidebar-width: 320px;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  transition: margin-left var(--transition-speed) ease;
  background: linear-gradient(rgba(17, 24, 39, 0.85), rgba(17, 24, 39, 0.85)), url('../image/bg2.webp');
  background-size: cover;
  background-position: center;
  /* fixed backgrounds are bad for mobile performance; only enable on large screens */
  background-attachment: scroll;
}

/* enable fixed background on large screens for visual effect */
@media (min-width: 1024px) {
  body {
    background-attachment: fixed;
  }
}

button,
a,
select,
input {
  font: inherit;
}

.sidebar,
.menu-toggle {
  font-family: 'Inter', sans-serif;
}

#overlay {
  position: fixed;
  inset: 0;
  background-color: rgba(0, 0, 0, 0.6);
  z-index: 998;
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--transition-speed) ease, visibility var(--transition-speed) ease;
}

#overlay.active {
  opacity: 1;
  visibility: visible;
}

.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  height: 100%;
  /* allow the sidebar to shrink on small viewports */
  width: min(var(--sidebar-width), 80%);
  background: var(--secondary-color);
  z-index: 999;
  padding: 15px;
  display: flex;
  flex-direction: column;
  transform: translateX(-100%);
  transition: transform var(--transition-speed) ease-in-out;
  box-shadow: 2px 0 10px rgba(0, 0, 0, 0.2);
}

.sidebar.active {
  transform: translateX(0);
}

.sidebar-header {
  display: flex;
  align-items: center;
  padding-bottom: 15px;
  margin-bottom: 15px;
  border-bottom: 1px solid var(--border-color);
}

.sidebar-header .logo-icon {
  font-size: 28px;
  color: var(--text-color);
  margin-right: 15px;
}

.sidebar-header .logo-text {
  font-size: 20px;
  font-weight: 600;
  color: var(--text-color);
}

.sidebar-nav {
  list-style: none;
  flex-grow: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 0;
  margin: 0;
}

.nav-item {
  margin-bottom: 5px;
}

.nav-link {
  display: flex;
  align-items: center;
  width: 100%;
  padding: 12px 15px;
  color: var(--text-color);
  text-decoration: none;
  border-radius: 8px;
  white-space: nowrap;
  cursor: pointer;
  border: 0;
  background: transparent;
  text-align: left;
}

.nav-link:hover,
.nav-link.active-link {
  background-color: var(--hover-color);
}

.nav-link .icon {
  font-size: 18px;
  min-width: 40px;
  text-align: center;
  margin-right: 10px;
}

.nav-link .text {
  font-weight: 400;
}

.nav-item.has-dropdown .nav-link {
  position: relative;
}

.dropdown-arrow {
  margin-left: auto;
  transition: transform 0.3s ease;
}

.nav-item.dropdown-active > .nav-link .dropdown-arrow {
  transform: rotate(90deg);
}

.submenu {
  list-style: none;
  padding-left: 25px;
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.35s ease-in-out;
}

.submenu-link {
  display: block;
  padding: 10px 20px;
  color: #adb5bd;
  text-decoration: none;
  border-radius: 5px;
  position: relative;
  cursor: pointer;
}

.submenu-link::before {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 5px;
  height: 5px;
  background-color: #adb5bd;
  border-radius: 50%;
}

.submenu-link:hover {
  background-color: var(--hover-color);
  color: white;
}

.menu-toggle {
  position: fixed;
  top: 20px;
  left: 20px;
  z-index: 1000;
  background: var(--primary-color);
  border: 1px solid var(--border-color);
  color: white;
  padding: 10px;
  cursor: pointer;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 45px;
  height: 45px;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
  transition: left var(--transition-speed) ease-in-out, transform 0.3s ease;
}

.menu-toggle:hover {
  transform: scale(1.1);
  background-color: var(--secondary-color);
}

.menu-toggle:focus-visible,
.nav-link:focus-visible,
.submenu-link:focus-visible,
button:focus-visible,
a:focus-visible,
select:focus-visible,
input:focus-visible {
  outline: 2px solid #22c55e;
  outline-offset: 2px;
}

.sidebar.active ~ .menu-toggle {
  left: calc(var(--sidebar-width) + 20px);
}

.menu-toggle .fa-bars,
.menu-toggle .fa-xmark {
  font-size: 24px;
  transition: transform 0.3s ease, opacity 0.3s ease;
  position: absolute;
}

/* Responsive tweaks for mobile */
@media (max-width: 768px) {
  :root {
    --sidebar-width: 280px;
  }

  .sidebar.active ~ .main-content {
    margin-left: 0;
  }

  .sidebar.active ~ .menu-toggle {
    left: calc(var(--sidebar-width) - 60px);
    color: var(--text-color);
    background: transparent;
    border: none;
    box-shadow: none;
  }

  /* make the menu toggle slightly larger on touch devices for better hit area */
  .menu-toggle {
    width: 52px;
    height: 52px;
  }

  /* allow the sidebar to cover most of the screen on small devices */
  .sidebar {
    width: 80vw;
  }
}

/* Ensure book cover images are responsive */
.book-cover img {
  width: 100%;
  height: auto;
  display: block;
  border-radius: 8px;
}

/* Reduce heavy shadows/transform on small screens for performance */
@media (max-width: 480px) {
  .book-cover img,
  .nav-link,
  .submenu-link {
    box-shadow: none;
    transition: none;
  }
}

/* --- New: widen layout aggressively to mimic desktop on many phones (Option 4) --- */
.books-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 1rem;
  align-items: start;
}

/* center items and limit their max width so they align like desktop grid */
.books-grid > * {
  justify-self: center;
  max-width: 320px;
  width: 100%;
}

/* container tweaks to make content feel wider on phones without changing viewport */
@media (max-width: 640px) {
  .container {
    width: 96%;
    max-width: none;
    padding-left: 12px;
    padding-right: 12px;
  }

  /* reduce header spacing so more grid is visible above the fold */
  .text-center {
    padding-top: 1rem;
    padding-bottom: 0.75rem;
  }

  .text-center > h1 {
    font-size: 1.6rem;
    line-height: 1.05;
    margin-bottom: 0.25rem;
  }

  .text-center > p {
    font-size: 0.95rem;
  }

  /* make search inputs and select fit better inline */
  .mb-10.w-full.max-w-lg.mx-auto.flex.flex-col.sm\:flex-row.gap-4 {
    gap: 0.6rem;
  }

  /* allow two/three columns on many phones like S23 FE */
  .books-grid {
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 0.9rem;
  }
}

/* Slightly larger columns for wider phones (phablets) */
@media (min-width: 360px) and (max-width: 639px) {
  .books-grid > * {
    max-width: 300px;
  }
}

@media (min-width: 640px) and (max-width: 1023px) {
  .books-grid {
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 1rem;
  }
}

/* keep a reasonable touch target for pagination buttons */
.pagination-touch-friendly button,
.pagination-touch-friendly a {
  min-width: 44px;
  min-height: 44px;
}
