/* ============================================================
   Islamic eBook Library — V8 Mobile UI & Discovery Polish
   Scoped exclusively to the public homepage (index.html).
   Layered atop public-v6.css and public-v7.css so desktop
   design quality and authenticated V3/V4 UI remain untouched.
   ============================================================ */

/* ---------- 1. Main Section Top Rhythm (No Category Gap) ---------- */
.main-section {
  padding-top: 24px;
}

/* ---------- 1B. Search Dropdown Layering & Scrollbar Fix ---------- */
.hero {
  overflow-x: clip;
  overflow-y: visible;
  z-index: 10;
}

.hero-inner {
  z-index: 5;
}

.hero-search {
  position: relative;
  z-index: 40;
}

.hero-stats {
  position: relative;
  z-index: 2;
}

.hs-suggestions {
  z-index: 80;
  top: calc(100% + 8px);
  left: 0;
  right: 0;
  width: 100%;
  box-sizing: border-box;
  max-height: min(52vh, 380px);
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  border-radius: 16px;
  border: 1px solid rgba(242, 217, 141, 0.45);
  background: rgba(23, 11, 46, 0.97);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  box-shadow: 0 22px 48px rgba(4, 1, 10, 0.72), 0 0 0 1px rgba(212, 175, 55, 0.14);
  padding: 6px;
  scrollbar-width: thin;
  scrollbar-color: rgba(212, 175, 55, 0.5) rgba(18, 7, 31, 0.75);
  animation: v8SugOpen 0.18s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.hs-suggestions[hidden] {
  display: none !important;
}

.hs-suggestions::-webkit-scrollbar {
  width: 7px;
}

.hs-suggestions::-webkit-scrollbar-track {
  background: rgba(18, 7, 31, 0.75);
  border-radius: 999px;
}

.hs-suggestions::-webkit-scrollbar-thumb {
  background: rgba(212, 175, 55, 0.45);
  border-radius: 999px;
  border: 1px solid rgba(23, 11, 46, 0.85);
}

.hs-suggestions::-webkit-scrollbar-thumb:hover {
  background: rgba(242, 217, 141, 0.72);
}

.hs-item.active,
.hs-item:focus-visible {
  background: rgba(212, 175, 55, 0.18);
  outline: 2px solid rgba(242, 217, 141, 0.65);
  outline-offset: -2px;
}

@keyframes v8SugOpen {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (max-width: 767px) {
  .hs-suggestions {
    max-height: min(44vh, 300px);
    border-radius: 14px;
  }
}

/* ---------- 2. Mobile & Narrow Tablet Header (<= 767px) ---------- */
@media (max-width: 767px) {
  .header-inner {
    min-height: 54px;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    padding: 6px 0;
    gap: 6px 8px;
  }

  .header-inner .logo {
    flex: 1 1 auto;
    min-width: 0;
    gap: 8px;
  }

  .logo-text {
    font-size: clamp(0.88rem, 3.8vw, 1rem);
    white-space: nowrap;
  }

  .header-inner .nav-auth:not(:empty) {
    order: 2;
    width: auto;
    flex: 0 0 auto;
    margin-left: auto;
    gap: 6px;
    justify-content: flex-end;
  }

  /* When logged in (avatar chip + logout), place auth controls on a compact
     second row so the website title never truncates on 320px-480px screens. */
  .header-inner .nav-auth:has(.nav-user-chip) {
    order: 4;
    flex: 1 0 100%;
    width: 100%;
    justify-content: space-between;
    padding-top: 4px;
    border-top: 1px solid rgba(212, 175, 55, 0.14);
  }

  .header-inner .nav-user-chip {
    min-height: 38px;
    padding: 4px 10px 4px 5px;
    gap: 6px;
    font-size: 0.78rem;
  }

  .header-inner .nav-avatar {
    width: 24px;
    height: 24px;
    font-size: 0.7rem;
    flex-shrink: 0;
  }

  .header-inner .nav-user-chip .nav-name {
    max-width: 82px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .header-inner .btn-login,
  .header-inner .btn-logout,
  .header-inner .nav-auth button,
  .header-inner .nav-auth a.btn-login {
    min-height: 38px;
    padding: 6px 12px;
    font-size: 0.8rem;
    white-space: nowrap;
  }

  .header-inner .mobile-menu {
    order: 3;
    flex: 0 0 auto;
    margin-left: 0;
  }

  .mobile-menu summary {
    min-height: 40px;
    min-width: 40px;
    padding: 6px 10px;
    justify-content: center;
  }
}

@media (max-width: 480px) {
  .container {
    width: calc(100% - 24px);
  }

  .header-inner {
    gap: 6px;
  }

  .logo-mark svg {
    width: 22px;
    height: 22px;
  }

  .header-inner .nav-user-chip .nav-name {
    max-width: 150px;
  }

  .header-inner .btn-login,
  .header-inner .btn-logout,
  .header-inner .nav-auth button {
    padding: 6px 10px;
    font-size: 0.76rem;
  }
}

@media (max-width: 360px) {
  .logo-text {
    font-size: 0.8rem;
  }

  .header-inner .nav-user-chip {
    padding: 4px 8px 4px 4px;
  }

  .header-inner .nav-user-chip .nav-name {
    max-width: 120px;
  }
}

/* ---------- 3. Mobile Hero Optimization (<= 767px) ---------- */
@media (max-width: 767px) {
  .hero {
    padding: 18px 0 18px;
    background-size: cover;
  }

  .hero-arch {
    top: 4px;
    width: calc(100% - 8px);
    height: 240px;
    opacity: 0.56;
  }

  .hero-lantern {
    display: block;
    width: 34px;
    height: 68px;
    opacity: 0.72;
  }
  .hero-lantern--left { left: 6px; }
  .hero-lantern--right { display: none; }

  .moon {
    right: 12px;
    top: 8px;
  }
  .moon svg {
    width: 40px;
    height: 40px;
  }

  .hero-inner {
    padding-top: 10px;
  }

  .hero-arabic {
    font-size: 1.18rem;
    margin-bottom: 5px;
  }

  .hero-eyebrow {
    font-size: 0.74rem;
    padding: 4px 12px;
    margin-bottom: 8px;
  }

  .hero h1 {
    font-size: clamp(1.56rem, 6.8vw, 2.15rem);
    line-height: 1.1;
    max-width: 18ch;
  }

  .hero-sub {
    font-size: 0.9rem;
    line-height: 1.48;
    margin-top: 10px;
    max-width: 36ch;
  }

  .hero-ctas {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    margin-top: 14px;
    width: min(360px, 100%);
  }

  .hero-ctas .btn-hero-primary {
    grid-column: 1 / -1;
    width: 100%;
    min-height: 44px;
  }

  .hero-ctas .btn-hero-secondary,
  .hero-ctas .hero-upload-btn {
    width: 100%;
    min-height: 44px;
    padding: 8px 10px;
    font-size: 0.84rem;
    justify-content: center;
  }

  .hero-search {
    margin-top: 14px;
    width: 100%;
  }

  .hero-stats {
    gap: 8px;
    margin-top: 14px;
  }

  .stat-card {
    min-height: 78px;
    padding: 9px 6px;
  }
}

@media (max-width: 360px) {
  .hero-lantern--left {
    display: none;
  }
}

/* ---------- 4. Mobile Book Discovery & Shelf Polish ---------- */
@media (max-width: 767px) {
  .main-section {
    padding-top: 18px;
    padding-bottom: 42px;
  }

  .home-sections {
    gap: 26px;
    margin-bottom: 30px;
  }

  .hr-scroll {
    gap: 14px;
    padding: 4px 2px 12px;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
  }

  .book-info {
    padding: 12px 12px 14px;
    gap: 5px;
  }

  .book-title {
    font-size: 0.92rem;
    line-height: 1.38;
    min-height: 2.76em;
  }

  .book-actions {
    gap: 6px;
    padding-top: 8px;
  }

  .book-actions .btn-download,
  .book-actions .btn-read-card {
    min-height: 40px;
    font-size: 0.8rem;
  }

  .shelf-nav {
    width: 42px;
    height: 42px;
  }

  .v7-back-to-top {
    right: 12px;
    bottom: calc(12px + env(safe-area-inset-bottom, 0px));
    width: 42px;
    height: 42px;
  }
}

@media (max-width: 429px) {
  .hr-card {
    flex: 0 0 70%;
  }
}

/* ---------- 5. Reduced Motion Safety ---------- */
@media (prefers-reduced-motion: reduce) {
  .hr-scroll {
    scroll-behavior: auto !important;
  }
  .hs-suggestions {
    animation: none !important;
  }
}
