/* ============================================
   MEGA MENU — Tabbed Genre Explorer
   ============================================ */

/* Trigger button in nav */
.mega-menu-trigger {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: none;
  border: none;
  cursor: pointer;
  font: inherit;
  padding: 0;
}

.mega-trigger-arrow {
  transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.mega-menu-trigger[aria-expanded="true"] .mega-trigger-arrow {
  transform: rotate(180deg);
}

/* Scroll links in nav */
.mega-scroll-link {
  cursor: pointer;
}

/* The mega menu panel */
.mega-menu {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 999;
  background: var(--bg-primary);
  border-bottom: 1px solid var(--border-color);
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.12), 0 4px 16px rgba(0, 0, 0, 0.06);
  opacity: 0;
  visibility: hidden;
  transform: translateY(-10px);
  transition: opacity 0.25s ease, visibility 0.25s ease, transform 0.25s ease;
  max-height: calc(100vh - 70px);
  overflow-y: auto;
}

.mega-menu.open {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.mega-menu-inner {
  display: flex;
  max-width: 1100px;
  margin: 0 auto;
  padding: 20px 32px;
  gap: 0;
}

/* Left: Tabs column */
.mega-menu-tabs {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 210px;
  max-width: 210px;
  padding-right: 20px;
  border-right: 1px solid var(--border-color);
}

.mega-tab {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 14px;
  border: none;
  background: none;
  border-radius: 10px;
  font-size: 13.5px;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  text-align: left;
  transition: background 0.15s ease, color 0.15s ease;
  white-space: nowrap;
}

.mega-tab:hover {
  background: var(--bg-secondary);
  color: var(--text-primary);
}

.mega-tab.active {
  background: rgba(99, 102, 241, 0.08);
  color: var(--color-primary);
  font-weight: 600;
}

.mega-tab-icon {
  display: flex;
  align-items: center;
  flex-shrink: 0;
  opacity: 0.6;
}

.mega-tab.active .mega-tab-icon {
  opacity: 1;
}

.mega-tab-divider {
  height: 1px;
  background: var(--border-color);
  margin: 6px 14px;
}

.mega-tab-quick {
  font-size: 13px;
}

/* Right: Panels — now stacked vertically */
.mega-menu-panels {
  flex: 1;
  padding-left: 28px;
  position: relative;
}

.mega-panel {
  display: none;
  animation: megaPanelIn 0.2s ease;
}

.mega-panel.active {
  display: flex;
  flex-direction: column;
  gap: 0;
}

@keyframes megaPanelIn {
  from { opacity: 0; transform: translateX(6px); }
  to   { opacity: 1; transform: translateX(0); }
}

/* Genre links — fill the width */
.mega-panel-genres {
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  gap: 6px 6px;
  padding-bottom: 16px;
}

.mega-genre-link {
  display: inline-flex;
  align-items: center;
  padding: 7px 16px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  background: var(--bg-secondary);
  border-radius: 20px;
  transition: background 0.15s ease, color 0.15s ease, transform 0.18s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.15s ease;
  text-decoration: none;
  white-space: nowrap;
}

.mega-genre-link:hover {
  background: rgba(99, 102, 241, 0.12);
  color: var(--color-primary);
  transform: scale(1.05);
  box-shadow: 0 2px 8px rgba(99, 102, 241, 0.1);
}

/* Featured section label */
.mega-panel-featured-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-secondary);
  opacity: 0.7;
  margin-bottom: 10px;
  padding-top: 12px;
  border-top: 1px solid var(--border-color);
}

/* Featured book cards — 2-column grid for more books */
.mega-panel-featured {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  max-width: none;
  min-width: auto;
}

.mega-panel-featured--wide {
  gap: 16px;
}

/* Book card — horizontal layout (cover left, info right) */
.mega-book-card {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  border-radius: 10px;
  padding: 8px 12px 8px 8px;
  background: var(--bg-secondary);
  transition: background 0.15s ease, transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.15s ease;
  flex: 1;
  min-width: 0;
}

.mega-book-card:hover {
  background: rgba(99, 102, 241, 0.06);
  transform: translateY(-2px);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
}

.mega-book-cover {
  width: 100px;
  min-width: 100px;
  height: auto;
  aspect-ratio: 2/3;
  object-fit: cover;
  border-radius: 6px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.mega-book-placeholder {
  width: 100px;
  min-width: 100px;
  aspect-ratio: 2/3;
  background: var(--bg-tertiary, #e5e7eb);
  border-radius: 5px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 9px;
  color: var(--text-secondary);
  text-align: center;
  padding: 4px;
}

.mega-book-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.mega-book-title {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.mega-book-author {
  font-size: 13px;
  color: var(--color-primary);
  font-weight: 500;
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mega-book-desc {
  font-size: 12px;
  color: var(--text-primary);
  opacity: 0.8;
  line-height: 1.4;
  margin-top: 2px;
}

/* Quick-link panel header */
.mega-panel-quick-header {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 16px;
  width: 100%;
}

.mega-panel-quick-icon {
  display: flex;
  color: var(--color-primary);
}

.mega-panel-scroll-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-top: 12px;
  font-size: 13px;
  font-weight: 600;
  color: var(--color-primary);
  text-decoration: none;
  transition: gap 0.15s ease;
}

.mega-panel-scroll-link:hover {
  gap: 8px;
}

/* Overlay behind mega menu */
.mega-menu-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.3);
  z-index: 998;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.25s ease, visibility 0.25s ease;
}

.mega-menu-overlay.open {
  opacity: 1;
  visibility: visible;
}


/* ============================================
   RESPONSIVE
   ============================================ */

@media (max-width: 900px) {
  .mega-menu-inner {
    flex-direction: column;
    padding: 16px 20px;
    gap: 16px;
  }

  .mega-menu-tabs {
    flex-direction: row;
    flex-wrap: wrap;
    min-width: auto;
    max-width: none;
    border-right: none;
    border-bottom: 1px solid var(--border-color);
    padding-right: 0;
    padding-bottom: 12px;
    gap: 4px;
  }

  .mega-tab {
    padding: 7px 12px;
    font-size: 12.5px;
  }

  .mega-tab-divider {
    display: none;
  }

  .mega-menu-panels {
    padding-left: 0;
    min-height: auto;
  }

  .mega-panel-featured {
    flex-direction: column;
    gap: 10px;
  }

  .mega-book-cover {
    width: 60px;
    min-width: 60px;
  }
}

@media (max-width: 767px) {
  .mega-menu-trigger,
  .mega-scroll-link {
    display: none !important;
  }

  .mega-menu {
    display: none !important;
  }
}

/* RTL support */
[dir="rtl"] .mega-menu-tabs {
  padding-right: 0;
  padding-left: 20px;
  border-right: none;
  border-left: 1px solid var(--border-color);
}

[dir="rtl"] .mega-menu-panels {
  padding-left: 0;
  padding-right: 28px;
}

[dir="rtl"] .mega-tab {
  text-align: right;
}

[dir="rtl"] .mega-book-card {
  padding: 8px 8px 8px 12px;
}

@media (max-width: 900px) {
  [dir="rtl"] .mega-menu-tabs {
    padding-left: 0;
    border-left: none;
  }

  [dir="rtl"] .mega-menu-panels {
    padding-right: 0;
  }
}
