/* ==========================================================================
   Mega Menu – compact, RTL, theme-aligned
   Matches header dropdowns: soft shadow, 16px radius, #33a1fd accents
   ========================================================================== */

/* Reset legacy megamenu rules from main.min.css that fight this layout */
.top-header-nav li .megamenu,
.top-header-nav li.has-child:hover .megamenu,
.top-header-two .top-header-nav li.has-child .megamenu,
.top-header-two .top-header-nav li.has-child:hover .megamenu {
  top: 120px !important;
  /* right/left are set by JS to align under the trigger item */
  left: auto !important;
  width: min(1100px, calc(100vw - 48px)) !important;
  max-width: 1100px !important;
  margin: 0 !important;
  border-radius: 16px !important;
  box-shadow: 0 24px 64px rgba(102, 119, 141, 0.14) !important;
  transform: translateY(8px) !important;
  z-index: 900 !important;
}

.top-header-nav li.megamenu-enabled:hover > .megamenu,
.top-header-nav li.megamenu-enabled.megamenu-open > .megamenu,
.top-header-nav li.has-child:hover > .megamenu,
.megamenu.megamenu-active {
  opacity: 1 !important;
  visibility: visible !important;
  transform: translateY(0) !important;
}

.top-header-nav li .megamenu:after {
  display: none !important;
}

.top-header-nav li .megamenu-tab-content-item {
  padding: 0 !important;
}

/* Legacy main.min.css forces display:flex — override with equal specificity */
.top-header-nav li .megamenu-tab-content-item.active {
  display: grid !important;
  grid-template-columns: 200px minmax(0, 1fr) !important;
  align-items: start !important;
  gap: 16px !important;
  height: auto !important;
  max-height: 100%;
  min-height: 0;
}

.top-header-nav li .megamenu-nav {
  height: auto !important;
  max-height: 360px !important;
  max-width: none !important;
  width: auto !important;
  min-width: 0 !important;
  gap: 8px !important;
  overflow: hidden !important;
}

.top-header-nav li .megamenu-nav a {
  display: flex !important;
  align-items: center !important;
  color: #586889;
  white-space: nowrap;
}

.top-header-nav li .megamenu-nav a:hover {
  color: #33a1fd;
}

.top-header-nav li .megamenu-courses {
  max-width: none !important;
  width: auto !important;
  min-width: 0 !important;
}

.megamenu,
.top-header-nav li .megamenu {
  --mm-primary: #33a1fd;
  --mm-muted: #8d9bb6;
  --mm-text: #586889;
  --mm-line: #ebecf2;
  --mm-soft: #f0f7fb;
  --mm-soft-2: #f7f8fc;
  --mm-dark: #282f3e;
  --mm-sale: #ff4a62;
  --mm-radius: 16px;
  --mm-shadow: 0 24px 64px rgba(102, 119, 141, 0.14);

  position: fixed !important;
  right: 24px; /* fallback; JS realigns under the trigger */
  background-color: #fff;
  border: 1px solid rgba(235, 236, 242, 0.9);
  transition: opacity .2s ease, visibility .2s ease, transform .2s ease;
  opacity: 0;
  visibility: hidden;
  overflow: hidden;
  font-family: inherit;
}

/* -------------------------------------------------------------------------- */
/* Inner layout                                                                */
/* -------------------------------------------------------------------------- */
.megamenu-inner {
  display: grid;
  grid-template-columns: 210px minmax(0, 1fr);
  align-items: stretch;
  min-height: 0;
  max-height: 400px;
}

/* -------------------------------------------------------------------------- */
/* Tabs column                                                                 */
/* -------------------------------------------------------------------------- */
.megamenu-tabs {
  background: var(--mm-soft-2);
  border-left: 1px solid var(--mm-line);
  padding: 10px 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow-y: auto;
  max-height: 400px;
}

.megamenu-tabs::-webkit-scrollbar { width: 4px; }
.megamenu-tabs::-webkit-scrollbar-thumb {
  background: var(--mm-line);
  border-radius: 999px;
}
.megamenu-tabs::-webkit-scrollbar-track { background: transparent; }

.megamenu-tabs-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 0;
  background: transparent;
  border-radius: 10px;
  color: var(--mm-text);
  font-size: 13px;
  font-weight: 500;
  line-height: 18px;
  text-align: right;
  cursor: pointer;
  transition: background .2s ease, color .2s ease;
  width: 100%;
}

.megamenu-tabs-item:hover {
  background: #fff;
  color: var(--mm-primary);
}

.megamenu-tabs-item.active {
  background: var(--mm-soft);
  color: var(--mm-primary);
}

.megamenu-tabs-item.active .megamenu-tabs-icon,
.megamenu-tabs-item:hover .megamenu-tabs-icon {
  background: #fff;
  color: var(--mm-primary);
  border-color: rgba(51, 161, 253, 0.2);
}

.megamenu-tabs-item.active .megamenu-tabs-count {
  color: var(--mm-primary);
}

.megamenu-tabs-item.active .megamenu-tabs-arrow,
.megamenu-tabs-item:hover .megamenu-tabs-arrow {
  color: var(--mm-primary);
  opacity: 1;
}

.megamenu-tabs-thumb,
.megamenu-tabs-icon {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  overflow: hidden;
  flex-shrink: 0;
  background: #fff;
  border: 1px solid var(--mm-line);
  color: var(--mm-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color .2s ease, color .2s ease, background .2s ease;
}

.megamenu-tabs-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.megamenu-tabs-icon i { font-size: 16px; line-height: 1; }

.megamenu-tabs-body {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
  align-items: flex-start;
}

.megamenu-tabs-label {
  font-weight: 600;
  font-size: 13px;
  line-height: 18px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.megamenu-tabs-meta {
  display: flex;
  align-items: center;
}

.megamenu-tabs-count {
  font-size: 10px;
  font-weight: 500;
  color: var(--mm-muted);
  background: transparent;
  padding: 0;
  border: 0;
}

.megamenu-tabs-arrow {
  font-size: 12px;
  color: var(--mm-muted);
  opacity: 0.55;
  flex-shrink: 0;
  transition: color .2s ease, opacity .2s ease;
}

/* -------------------------------------------------------------------------- */
/* Tab content                                                                 */
/* -------------------------------------------------------------------------- */
.megamenu-tab-content {
  padding: 12px 14px 14px;
  background: #fff;
  overflow: hidden;
  min-width: 0;
  min-height: 0;
}

.megamenu-tab-content-item {
  display: none;
  gap: 16px;
  animation: megamenuFadeIn .2s ease;
}

.megamenu-tab-content-item.active {
  display: grid;
  grid-template-columns: 200px minmax(0, 1fr);
  align-items: start;
  min-height: 0;
}

/* -------------------------------------------------------------------------- */
/* Subcategory nav — scrolls independently so slides keep a stable height      */
/* -------------------------------------------------------------------------- */
.megamenu-nav {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
  max-height: 360px;
  border-left: 1px solid var(--mm-line);
  padding-left: 12px;
  overflow: hidden;
}

.megamenu-nav-header {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 2px;
  flex-shrink: 0;
}

.megamenu-nav-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-weight: 600;
  color: var(--mm-muted);
  white-space: nowrap;
}

.megamenu-nav-badge::before {
  content: "";
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--mm-primary);
  flex-shrink: 0;
}

.megamenu-nav-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  align-content: start;
  overflow-y: auto;
  overflow-x: hidden;
  min-height: 0;
  flex: 1 1 auto;
  padding-left: 2px;
}

.megamenu-nav-list::-webkit-scrollbar { width: 4px; }
.megamenu-nav-list::-webkit-scrollbar-thumb {
  background: var(--mm-line);
  border-radius: 999px;
}
.megamenu-nav-list::-webkit-scrollbar-track { background: transparent; }

.megamenu-nav-link {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 8px;
  border-radius: 8px;
  color: var(--mm-text);
  font-size: 12px;
  font-weight: 500;
  line-height: 18px;
  transition: background .2s ease, color .2s ease;
  background: transparent;
  min-width: 0;
}

.megamenu-nav-link:hover {
  background: var(--mm-soft);
  color: var(--mm-primary);
}

.megamenu-nav-link-dot {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--mm-line);
  flex-shrink: 0;
}

.megamenu-nav-link:hover .megamenu-nav-link-dot {
  background: var(--mm-primary);
}

.megamenu-nav-link-label {
  flex: 1 1 auto;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.megamenu-nav-count {
  font-size: 10px;
  font-weight: 500;
  color: var(--mm-muted);
  background: var(--mm-soft-2);
  padding: 1px 6px;
  border-radius: 999px;
  flex-shrink: 0;
}

.megamenu-nav-link-all {
  color: var(--mm-primary);
  font-weight: 600;
  margin-top: 4px;
}

.megamenu-nav-link-all:hover {
  background: rgba(51, 161, 253, 0.08);
}

.megamenu-nav-link-all i { font-size: 12px; }

/* -------------------------------------------------------------------------- */
/* Course column                                                               */
/* -------------------------------------------------------------------------- */
.megamenu-courses {
  position: relative;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.megamenu-courses-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
  flex-shrink: 0;
}

.megamenu-courses-badge {
  font-size: 10px;
  font-weight: 600;
  color: #fff;
  background: var(--mm-sale);
  padding: 2px 7px;
  border-radius: 6px;
  flex-shrink: 0;
}

.megamenu-courses-swiper,
.megamenu-swiper {
  position: relative;
  overflow: hidden;
  padding: 0;
  min-height: 0;
  flex: 1 1 auto;
  width: 100%;
  max-width: 100%;
}

.megamenu-courses-swiper .swiper-wrapper {
  align-items: flex-start;
  box-sizing: border-box;
}

.megamenu-courses-swiper .swiper-slide {
  height: auto;
  box-sizing: border-box;
  max-width: 100%;
  flex-shrink: 0;
}

/* Stable width before Swiper initializes (avoids full-width flash) */
.megamenu-courses-swiper:not(.swiper-initialized) .swiper-slide {
  width: calc((100% - 24px) / 3);
  margin-left: 12px;
}

.megamenu-courses-nav {
  position: static;
  display: flex;
  gap: 4px;
  z-index: 5;
}

.megamenu-courses-prev,
.megamenu-courses-next {
  position: static !important;
  width: 26px;
  height: 26px;
  border-radius: 8px;
  background: #fff;
  color: var(--mm-text);
  border: 1px solid var(--mm-line);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all .2s ease;
  margin: 0 !important;
}

.megamenu-courses-prev::after,
.megamenu-courses-next::after { display: none; }

.megamenu-courses-prev:hover,
.megamenu-courses-next:hover {
  background: var(--mm-primary);
  color: #fff;
  border-color: var(--mm-primary);
}

.megamenu-courses-prev.swiper-button-disabled,
.megamenu-courses-next.swiper-button-disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.megamenu-courses-prev i,
.megamenu-courses-next i { font-size: 12px; }

/* -------------------------------------------------------------------------- */
/* Course cards — compact so footers fit within panel height                   */
/* -------------------------------------------------------------------------- */
.megamenu-courses .course {
  background: #fff;
  border-radius: 12px;
  padding: 8px;
  box-shadow: none;
  border: 1px solid var(--mm-line);
  transition: border-color .2s ease, box-shadow .2s ease;
  height: auto;
  display: flex;
  flex-direction: column;
}

.megamenu-courses .course:hover {
  transform: none;
  box-shadow: 0 8px 20px -12px rgba(102, 119, 141, 0.2);
  border-color: rgba(51, 161, 253, 0.35);
}

.megamenu-courses .course-image {
  margin-bottom: 6px;
  border-radius: 10px;
  overflow: hidden;
  position: relative;
  flex-shrink: 0;
}

.megamenu-courses .course-image img {
  border-radius: 10px !important;
  width: 100%;
  height: 120px !important;
  aspect-ratio: auto;
  object-fit: cover;
  transition: transform .35s ease;
}

.megamenu-courses .course:hover .course-image img {
  transform: scale(1.03);
}

.megamenu-courses .course-image .offer {
  background: var(--mm-sale) !important;
  color: #fff !important;
  width: auto !important;
  height: auto !important;
  padding: 2px 6px !important;
  font-size: 10px !important;
  font-weight: 700;
  border-radius: 5px !important;
  box-shadow: none;
}

.megamenu-courses .course-content {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0;
}

.megamenu-courses .course-content h2 {
  font-size: 12px !important;
  font-weight: 600;
  margin: 0 0 4px !important;
  line-height: 18px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.megamenu-courses .course-content h2 a {
  color: var(--mm-dark);
  transition: color .2s ease;
}

.megamenu-courses .course-content h2 a:hover { color: var(--mm-primary); }

.megamenu-courses .course-content .date-star {
  font-size: 10px !important;
  color: var(--mm-muted);
  padding-bottom: 4px;
  margin-bottom: 4px;
  border-bottom: 1px dashed var(--mm-line);
}

.megamenu-courses .course-content .teacher-students {
  font-size: 10px !important;
  color: var(--mm-muted);
  padding-bottom: 0;
  margin-bottom: 0;
  border-bottom: 0;
}

/* Hide price row in mega menu to keep cards short */
.megamenu-courses .course-content .price {
  display: none !important;
}

/* -------------------------------------------------------------------------- */
/* Responsive                                                                  */
/* -------------------------------------------------------------------------- */
@media only screen and (max-width: 1199px) {
  .megamenu,
  .top-header-nav li .megamenu {
    width: min(980px, calc(100vw - 32px)) !important;
    max-width: 980px !important;
  }

  .megamenu-inner {
    grid-template-columns: 190px minmax(0, 1fr);
    max-height: 360px;
  }

  .megamenu-tabs { max-height: 360px; }

  .top-header-nav li .megamenu-tab-content-item.active,
  .megamenu-tab-content-item.active {
    grid-template-columns: 170px minmax(0, 1fr) !important;
  }

  .megamenu-courses .course-image img {
    height: 108px !important;
  }
}

@media only screen and (max-width: 991px) {
  .megamenu { display: none !important; }
}

@keyframes megamenuFadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}
