/* Modern Digital Library Theme */
:root {
  --lib-primary: #1e3a8a; /* Academic Blue */
  --lib-secondary: #3b82f6; /* Bright accent blue */
  --lib-dark: #0f172a;
  --lib-light: #f1f5f9;
  --lib-text: #334155;
  --lib-header-font: "Merriweather", serif; /* Scholarly feel */
  --lib-body-font: "Inter", sans-serif;
  --lib-radius: 8px; /* Sharper, more professional corners */
  --lib-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

body {
  background-color: #f8fafc;
  font-family: var(--lib-body-font) !important;
  color: var(--lib-text);
  -webkit-user-select: none; /* Safari */
  -ms-user-select: none; /* IE 10 and IE 11 */
  user-select: none; /* Standard syntax */
  overflow-x: hidden;
}

html {
  overflow-x: hidden;
}

input,
textarea {
  -webkit-user-select: auto !important;
  -ms-user-select: auto !important;
  user-select: auto !important;
}

h1,
h2,
h3,
h4,
h5,
h6 {
  font-family: var(--lib-header-font);
  color: var(--lib-dark);
}

/* --- Library Header --- */
.library-header {
  background: var(--lib-dark);
  padding: 0.35rem 0; /* Slightly tighter */
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
  z-index: 1100 !important;
  width: 100%;
  overflow: hidden;
}

/* ... existing code ... */

/* --- Mobile & Responsive Tweaks --- */
@media (max-width: 768px) {
  /* Horizontal Scroll for Projects on Mobile */
  .row-cols-md-2 {
    display: flex;
    flex-wrap: nowrap;
    overflow-x: auto;
    padding-bottom: 1.5rem; /* More space for scrollbar */
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
    margin-right: -15px; /* Offset bootstrap margin */
    margin-left: -5px; /* Slight left pull */
  }

  .row-cols-md-2::-webkit-scrollbar {
    height: 6px;
  }

  .row-cols-md-2::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 10px;
  }

  .row-cols-md-2 > .col {
    flex: 0 0 85%; /* SHow 85% of card to encourage scroll */
    max-width: 85%;
    scroll-snap-align: center;
  }

  .library-sidebar {
    margin-bottom: 2rem;
  }

  /* Order change class for mobile filtering */
  .mobile-filter-order {
    order: -1 !important;
  }
}

/* Ensure all links and text in header are white-ish */
.library-header,
.library-header a,
.navbar-dark .navbar-nav .nav-link {
  color: rgba(255, 255, 255, 0.9);
}

.library-header a:hover,
.navbar-dark .navbar-nav .nav-link:hover {
  color: white;
}
.library-nav-link {
  color: rgba(255, 255, 255, 0.8) !important; /* Light text for dark bg */
  font-weight: 600;
  padding: 0.3rem 0.6rem !important; /* Reduced padding */
  position: relative;
  font-family: var(--lib-body-font);
  white-space: nowrap;
}

.library-nav-link:hover {
  color: #fff !important;
}

.library-nav-link::after {
  content: "";
  position: absolute;
  width: 0;
  height: 2px;
  bottom: 0;
  left: 50%;
  background-color: var(--lib-primary);
  transition: all 0.3s ease;
  transform: translateX(-50%);
}

.library-nav-link:hover::after {
  width: 80%;
}

.bar {
  background-color: #fff; /* White hamburger bars */
}

/* --- Hero Search Section --- */
.library-hero {
  /* Background image with a dark gradient overlay for text readability */
  background:
    linear-gradient(rgba(15, 23, 42, 0.7), rgba(243, 187, 123, 0)),
    url("/static/assets/img/lib.jpg");
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  padding: 6rem 0; /* Slightly increased padding */
  color: white;
  text-align: center;
  position: relative;
  overflow: hidden;
}

/* This nav has too many items (7 links + 3 CTA buttons) to fit horizontally
   before very wide screens, so force the off-canvas drawer all the way up
   to 1599px instead of relying on Bootstrap's built-in xl (1200px) breakpoint. */
@media (max-width: 1599.98px) {
  .library-header .navbar-toggler {
    display: block !important;
  }
  .library-header .navbar-collapse {
    display: none !important;
  }
  .library-header .navbar-collapse.show {
    display: block !important;
  }
}

/* Drawer-only chrome — hidden on the wide horizontal nav, shown by the
   off-canvas media query below. */
.nav-drawer-header {
  display: none !important;
}

/* Dimmed backdrop behind the off-canvas drawer, so the page underneath
   doesn't visually bleed through the uncovered edge while the menu is open. */
.nav-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 1040; /* below the drawer (1050), above the page content */
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s ease;
}

/* --- Off-Canvas Mobile Navigation --- */
@media (max-width: 1599.98px) {
  .nav-backdrop.show {
    opacity: 1;
    visibility: visible;
  }

  .navbar-collapse {
    position: fixed;
    top: 0;
    right: -100%; /* Hidden by default */
    width: 85%;
    max-width: 380px; /* Cap drawer width on very wide "mobile-mode" viewports */
    height: 100vh;
    background: var(--lib-dark); /* Dark Match */
    z-index: 1050;
    transition: right 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    padding: 2.25rem 1.5rem 2rem;
    box-shadow: -10px 0 30px rgba(0, 0, 0, 0.5);
    display: block !important; /* Force block to allow transition */
    visibility: hidden;
    overflow-y: auto;
  }

  .navbar-collapse.show {
    right: 0;
    visibility: visible;
  }

  .nav-drawer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-bottom: 1.5rem;
    margin-bottom: 1.75rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.14);
  }

  .nav-drawer-title {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    color: #fff;
    font-weight: 700;
    font-size: 1.05rem;
    letter-spacing: 0.3px;
  }

  .nav-drawer-brand-icon {
    height: 24px;
    width: auto;
    display: block;
  }

  /* Compact 2-column tile grid for the plain nav links */
  .navbar-collapse .navbar-nav {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.6rem;
    width: 100%;
    margin-top: 0.25rem;
  }

  .navbar-collapse .nav-item {
    width: 100%;
    margin: 0;
  }

  .navbar-collapse .library-nav-link {
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    width: 100%;
    height: 100%;
    min-height: 54px;
    padding: 0.75rem 0.6rem !important;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(255, 255, 255, 0.03);
    font-size: 0.92rem;
    font-weight: 600;
    letter-spacing: 0.2px;
    line-height: 1.25;
  }

  .navbar-collapse .library-nav-link::after {
    display: none;
  }

  .navbar-collapse .library-nav-link:hover {
    background: rgba(255, 255, 255, 0.07);
    border-color: rgba(255, 255, 255, 0.16);
  }

  .navbar-collapse .library-nav-link.active {
    background: rgba(59, 130, 246, 0.16);
    border-color: rgba(59, 130, 246, 0.5);
    color: #fff !important;
  }

  /* CTA row spans the full grid width, visually separated from the link tiles */
  .navbar-collapse .nav-cta-item {
    grid-column: 1 / -1;
    margin-top: 0.75rem;
    padding-top: 1.1rem;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
  }

  .navbar-collapse .upload-btn {
    display: flex;
    width: 100%;
    justify-content: center;
    text-align: center;
    padding: 1rem 1.5rem !important;
    font-size: 1rem;
    letter-spacing: 0.3px;
  }

  .navbar-collapse h5 {
    color: white !important; /* Menu title white */
  }

  .close-nav {
    color: white !important;
    background: rgba(255, 255, 255, 0.08);
    border: none;
    width: 32px;
    height: 32px;
    min-width: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
    cursor: pointer;
    transition: background 0.2s ease;
  }

  .close-nav:hover {
    background: rgba(255, 255, 255, 0.18);
  }

  /* --- Robust Standard Hamburger --- */
  .custom-toggler {
    border: none !important;
    background: transparent !important;
    padding: 0 !important;
    cursor: pointer;
    z-index: 1200;
    position: relative;
    width: 30px;
    height: 22px;
    display: block !important;
    margin-left: auto;
  }

  .custom-toggler:focus {
    outline: none;
  }

  .bar {
    position: absolute;
    left: 0;
    width: 100%;
    height: 3px;
    background-color: white !important;
    border-radius: 3px;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  }

  .bar1 {
    top: 0;
  }
  .bar2 {
    top: 9px;
  }
  .bar3 {
    top: 18px;
  }

  /* Morph to X */
  .custom-toggler.change .bar1 {
    top: 9px;
    transform: rotate(45deg) !important;
  }
  .custom-toggler.change .bar2 {
    opacity: 0 !important;
    left: -10px !important;
  }
  .custom-toggler.change .bar3 {
    top: 9px;
    transform: rotate(-45deg) !important;
  }
}

@keyframes float {
  0% {
    transform: translateY(0) rotate(0deg);
    opacity: 0;
  }
  10% {
    opacity: 0.4; /* Visible but not blocking text */
  }
  90% {
    opacity: 0.4;
  }
  100% {
    transform: translateY(-120vh) rotate(720deg);
    opacity: 0;
  }
}

.hero-search-box {
  background: white;
  padding: 0.5rem;
  border-radius: 50px;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
  display: flex;
  max-width: 700px;
  margin: 0 auto;
}

.hero-search-input {
  border: none;
  flex-grow: 1;
  padding: 0 1.5rem;
  font-size: 1.1rem;
  outline: none;
  border-radius: 50px 0 0 50px;
}

.hero-search-btn {
  background: var(--lib-primary);
  color: white;
  border: none;
  padding: 0.8rem 2rem;
  border-radius: 50px;
  font-weight: 600;
  transition: all 0.3s;
}

.hero-search-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 5px 15px rgba(30, 58, 138, 0.3);
}

/* --- Floating Telegram Community Button --- */
.telegram-fab {
  position: fixed;
  bottom: 86px; /* stacked above the back-to-top button */
  right: 20px;
  z-index: 998;
  width: 54px;
  height: 54px;
  border-radius: 50%;
  background: linear-gradient(135deg, #2aabee 0%, #0088cc 100%);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  box-shadow: 0 6px 20px rgba(0, 136, 204, 0.45);
  text-decoration: none !important;
  transition: transform 0.25s ease, box-shadow 0.25s ease;
}

.telegram-fab:hover {
  color: white;
  transform: translateY(-3px);
  box-shadow: 0 10px 26px rgba(0, 136, 204, 0.55);
}

.telegram-fab-ping {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 2px solid rgba(42, 171, 238, 0.6);
  animation: telegramPing 2.2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
  pointer-events: none;
}

@keyframes telegramPing {
  0% {
    transform: scale(1);
    opacity: 0.7;
  }
  100% {
    transform: scale(1.5);
    opacity: 0;
  }
}

@media (max-width: 480px) {
  .telegram-fab {
    width: 48px;
    height: 48px;
    font-size: 1.3rem;
    bottom: 78px;
    right: 16px;
  }
}

/* --- Back to Top Button --- */
.u-go-to-modern {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 999;
  width: 50px;
  height: 50px;
  background: var(--lib-primary);
  color: white;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px rgba(30, 58, 138, 0.3);
  opacity: 0;
  visibility: hidden;
  transform: translateY(20px);
  transition: all 0.3s ease;
  text-decoration: none !important;
}

.u-go-to-modern.show {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.u-go-to-modern:hover {
  background: #1e40af; /* Darker blue */
  color: white;
  transform: translateY(-3px);
  box-shadow: 0 6px 15px rgba(30, 58, 138, 0.4);
}

/* --- Floating Background Shapes --- */
.floating-shapes {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  z-index: -1; /* Behind everything */
  pointer-events: none;
}

.shape {
  position: absolute;
  color: var(--lib-secondary); /* Bright Blue */
  font-size: 2rem;
  animation: float 25s infinite linear;
  bottom: -100px; /* Start below screen */
  opacity: 0;
}

/* Specific Shapes */
.shape-1 {
  left: 5%;
  animation-duration: 25s;
  animation-delay: 0s;
  font-size: 3rem;
}
.shape-2 {
  left: 15%;
  animation-duration: 35s;
  animation-delay: 2s;
  font-size: 1.5rem;
}
.shape-3 {
  left: 25%;
  animation-duration: 30s;
  animation-delay: 5s;
  font-size: 4rem;
}
.shape-4 {
  left: 35%;
  animation-duration: 28s;
  animation-delay: 1s;
  font-size: 2.5rem;
}
.shape-5 {
  left: 45%;
  animation-duration: 32s;
  animation-delay: 7s;
  font-size: 3.5rem;
}
.shape-6 {
  left: 55%;
  animation-duration: 22s;
  animation-delay: 3s;
  font-size: 2rem;
}
.shape-7 {
  left: 65%;
  animation-duration: 29s;
  animation-delay: 6s;
  font-size: 2.8rem;
}
.shape-8 {
  left: 75%;
  animation-duration: 33s;
  animation-delay: 4s;
  font-size: 1.8rem;
}
.shape-9 {
  left: 85%;
  animation-duration: 26s;
  animation-delay: 0s;
  font-size: 3.2rem;
}
.shape-10 {
  left: 95%;
  animation-duration: 31s;
  animation-delay: 2s;
  font-size: 2.2rem;
}
/* --- Sidebar Layout --- */
.library-sidebar {
  background: white;
  border-radius: var(--lib-radius);
  padding: 1.5rem;
  box-shadow: var(--lib-shadow);
  border: 1px solid #e2e8f0;
  z-index: 100 !important; /* Ensure it stays below navbar */
}

.sidebar-title {
  font-size: 1.1rem;
  border-bottom: 2px solid #e2e8f0;
  padding-bottom: 0.5rem;
  margin-bottom: 1rem;
  color: var(--lib-primary);
}

.sidebar-link {
  display: block;
  padding: 0.5rem 0;
  color: var(--lib-text);
  transition: color 0.2s;
  text-decoration: none;
}

.sidebar-link:hover,
.sidebar-link.active {
  color: var(--lib-primary);
  font-weight: 600;
  padding-left: 5px; /* Indent */
  text-decoration: none;
}

/* --- List View Item --- */
.lib-item-card {
  background: #f8fafc; /* Slightly darker than white */
  border-radius: var(--lib-radius);
  padding: 1.5rem;
  margin-bottom: 1.5rem;
  box-shadow:
    0 10px 15px -3px rgba(0, 0, 0, 0.1),
    0 4px 6px -2px rgba(0, 0, 0, 0.05); /* Stronger shadow */
  transition:
    transform 0.2s,
    box-shadow 0.2s;
  border-left: 4px solid transparent;
}

.lib-item-card:hover {
  transform: translateY(-5px); /* Slightly more lift */
  box-shadow:
    0 20px 25px -5px rgba(0, 0, 0, 0.1),
    0 10px 10px -5px rgba(0, 0, 0, 0.04);
  border-left-color: var(--lib-secondary);
}

.lib-item-meta {
  font-size: 0.9rem;
  color: #64748b;
  margin-bottom: 0.5rem;
}

.lib-item-title {
  font-size: 1.4rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
}

.lib-item-title a {
  color: var(--lib-dark);
  text-decoration: none;
}

.lib-item-title a:hover {
  color: var(--lib-primary);
}

.lib-badge {
  background: #eff6ff;
  color: var(--lib-primary);
  padding: 0.25rem 0.75rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  display: inline-block;
}

/* --- Stats Counters --- */
.stat-card {
  text-align: center;
  padding: 2rem;
  background: white;
  border-radius: var(--lib-radius);
}

.stat-number {
  font-size: 2.5rem;
  font-weight: 700;
  color: var(--lib-primary);
  font-family: var(--lib-body-font);
}

/* --- Footer --- */
.library-footer {
  background: var(--lib-dark);
  color: #94a3b8;
  padding: 3rem 0;
  margin-top: 0; /* Closed gap as requested */
}

.footer-heading {
  color: white;
  font-family: var(--lib-header-font);
  margin-bottom: 1.5rem;
}
