/**
 * Megamenu Frontend Styles
 * 
 * Styles cho megamenu hiển thị frontend
 * Class prefix: tp-mm- (TanPhat MegaMenu)  
 * 
 * @package TanPhat
 * @version 1.0.0
 */

/* ================================
   MEGAMENU WRAPPER
   ================================ */

.tp-mm-megamenu-wrapper {
  position: fixed;
  top: 100%;
  left: 0;
  z-index: 99999;
  opacity: 0;
  visibility: hidden;
  width: 100%;
}

/* ================================
   MEGAMENU CONTAINER
   ================================ */

.tp-mm-megamenu {
  min-width: 600px;
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: 12px;
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1),
    0 10px 10px -5px rgba(0, 0, 0, 0.04);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  overflow: hidden;
}

.tp-mm-megamenu-wrapper--active {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.tp-mm-megamenu-wrapper--animating-in {
  animation: tpMegamenuFadeIn 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.tp-mm-megamenu-wrapper--animating-out {
  animation: tpMegamenuFadeOut 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes tpMegamenuFadeIn {
  0% {
    opacity: 0;
    transform: translateY(-10px) scale(0.98);
  }
  100% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes tpMegamenuFadeOut {
  0% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
  100% {
    opacity: 0;
    transform: translateY(-5px) scale(0.98);
  }
}

/* ================================
   MEGAMENU STRUCTURE
   ================================ */

.tp-mm-megamenu__container {
  padding: 0;
}

.tp-mm-megamenu__content {
  display: flex;
  min-height: 200px;
}

/* ================================
   MENU SECTION
   ================================ */

.tp-mm-megamenu__menu {
  flex: 1;
  padding: 32px;
  display: flex;
  flex-direction: column;
}

.tp-mm-megamenu__menu--left {
  order: 1;
  border-right: 1px solid var(--gray-100);
}

.tp-mm-megamenu__menu--right {
  order: 2;
  border-left: 1px solid var(--gray-100);
}

.tp-mm-megamenu__grid {
  display: grid;
  gap: 24px;
  height: 100%;
}

.tp-mm-megamenu__grid--1-cols {
  grid-template-columns: 1fr;
}

.tp-mm-megamenu__grid--2-cols {
  grid-template-columns: repeat(2, 1fr);
}

.tp-mm-megamenu__grid--3-cols {
  grid-template-columns: repeat(3, 1fr);
}

/* Remove column wrapper - no longer needed with pure CSS Grid */
/* .tp-mm-megamenu__column removed */

/* ================================
   MENU GROUPS - Now direct grid items
   ================================ */

.tp-mm-megamenu__group {
  /* Each group is now a grid item */
  display: flex;
  flex-direction: column;
  align-self: start; /* Prevent stretching */
}

/* No need for margin-bottom since grid handles spacing via gap */

.tp-mm-megamenu__group-header {
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--primary-color);
}

.tp-mm-megamenu__group-title {
  display: block;
  text-decoration: none;
  color: var(--text-primary);
  font-size: var(--font-size-base);
  font-weight: var(--font-weight-bold);
  line-height: var(--line-height-tight);
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  letter-spacing: var(--letter-spacing-tight);
}

.tp-mm-megamenu__group-title:hover {
  color: var(--primary-color);
  text-decoration: none;
  transform: translateX(2px);
}

.tp-mm-megamenu__group-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

/* ================================
   MENU LISTS (Legacy)
   ================================ */

.tp-mm-megamenu__list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.tp-mm-megamenu__list-item {
  margin: 0;
  padding: 0;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  border-radius: 6px;
}

.tp-mm-megamenu__list-item:hover {
  transform: translateX(4px);
  background: var(--gray-50);
}

.tp-mm-megamenu__list-item.tp-mm-item--highlighted {
  background: var(--primary-s-light);
  transform: scale(1.02);
}

/* ================================
   MENU LINKS
   ================================ */

.tp-mm-megamenu__link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  text-decoration: none;
  color: var(--text-primary);
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  line-height: var(--line-height-tight);
  border-radius: 8px;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  overflow: hidden;
}

.tp-mm-megamenu__link:hover {
  color: var(--primary-color);
  background: var(--primary-s-light);
  text-decoration: none;
}

.tp-mm-megamenu__link:focus {
  outline: 2px solid var(--primary-color);
  outline-offset: 2px;
  color: var(--primary-color);
}

.tp-mm-megamenu__link:active {
  transform: scale(0.98);
}

/* ================================
   MENU LINK CONTENT
   ================================ */

.tp-mm-megamenu__item-icon {
  font-size: 16px;
  color: var(--primary-color);
  flex-shrink: 0;
  opacity: 0.8;
  transition: all 0.2s ease;
}

.tp-mm-megamenu__link:hover .tp-mm-megamenu__item-icon {
  opacity: 1;
  transform: scale(1.1);
}

.tp-mm-megamenu__item-text {
  flex: 1;
  font-weight: var(--font-weight-semibold);
  letter-spacing: var(--letter-spacing-tight);
}

.tp-mm-megamenu__item-desc {
  display: block;
  font-size: var(--font-size-xs);
  color: var(--text-secondary);
  margin-top: 2px;
  line-height: var(--line-height-tight);
  font-weight: var(--font-weight-normal);
}

/* ================================
   IMAGE SECTION
   ================================ */

.tp-mm-megamenu__image {
  flex: 0 0 280px;
  position: relative;
  overflow: hidden;
}

.tp-mm-megamenu__image--left {
  order: 1;
}

.tp-mm-megamenu__image--right {
  order: 2;
}

.tp-mm-megamenu__image-wrapper {
  position: relative;
  width: 100%;
  height: 100%;
}

.tp-mm-megamenu__bg-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.tp-mm-megamenu__image:hover .tp-mm-megamenu__bg-image {
  transform: scale(1.05);
}

.tp-mm-megamenu__image-overlay {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.7));
  color: var(--white);
  padding: 24px;
  transform: translateY(10px);
  opacity: 0;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.tp-mm-megamenu__image:hover .tp-mm-megamenu__image-overlay {
  transform: translateY(0);
  opacity: 1;
}

/* ================================
   MEGAMENU VARIANTS
   ================================ */

/* Compact variant */
.tp-mm-megamenu--compact .tp-mm-megamenu__menu {
  padding: 20px;
}

.tp-mm-megamenu--compact .tp-mm-megamenu__link {
  padding: 8px 12px;
  font-size: var(--font-size-xs);
}

.tp-mm-megamenu--compact .tp-mm-megamenu__image {
  flex: 0 0 200px;
}

/* Wide variant */
.tp-mm-megamenu--wide {
  min-width: 800px;
}

.tp-mm-megamenu--wide .tp-mm-megamenu__image {
  flex: 0 0 360px;
}

/* ================================
   PARENT ITEM STATES
   ================================ */

.tp-mm-item--megamenu {
  position: relative;
}

/* Hide default submenu for megamenu items */
.tp-mm-item--megamenu .custom-header__submenu {
  display: none !important;
}

.tp-mm-item--megamenu > .tp-mm-link {
  position: relative;
}

.tp-mm-item--megamenu.tp-mm-item--active > .tp-mm-link {
  color: var(--primary-color);
  background: var(--primary-s-light);
}

/* Megamenu Arrow Icon - Match với header style */
.tp-mm-item--megamenu .custom-header__dropdown-icon {
  margin-left: 0.5rem;
  font-size: 0.75rem;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  color: white;
}

.tp-mm-item--megamenu:hover .custom-header__dropdown-icon {
  color: var(--primary-color);
}

.tp-mm-item--megamenu.tp-mm-item--active .custom-header__dropdown-icon {
  transform: rotate(180deg);
  color: var(--primary-color);
}

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

/* Tablet */
@media (max-width: 1024px) {
  .tp-mm-megamenu-wrapper {
    position: fixed;
    top: 70px;
    left: 0;
    right: 0;
    width: 100%;
  }

  .tp-mm-megamenu-wrapper__container {
    padding: 0;
  }

  .tp-mm-megamenu {
    min-width: unset;
    width: 100%;
    max-height: calc(100vh - var(--header-height, 80px));
    overflow-y: auto;
    border-radius: 0;
  }

  .tp-mm-megamenu-wrapper--active {
    transform: translateY(0);
  }

  .tp-mm-megamenu__content {
    flex-direction: column;
    min-height: unset;
  }

  .tp-mm-megamenu__menu {
    order: 1;
    padding: 24px;
    border-right: none;
    border-left: none;
    border-bottom: 1px solid var(--gray-100);
  }

  .tp-mm-megamenu__image {
    order: 2;
    flex: 0 0 200px;
  }

  .tp-mm-megamenu__grid--2-cols,
  .tp-mm-megamenu__grid--3-cols {
    grid-template-columns: 1fr;
    gap: 16px;
  }
}

/* Mobile */
@media (max-width: 640px) {
  .tp-mm-megamenu-wrapper {
    top: calc(var(--header-height, 80px) - 1px);
  }

  .tp-mm-megamenu {
    border-radius: 0;
  }

  .tp-mm-megamenu__menu {
    padding: 20px;
  }

  .tp-mm-megamenu__link {
    padding: 16px 12px;
    font-size: var(--font-size-sm);
  }

  .tp-mm-megamenu__image {
    flex: 0 0 160px;
  }

  .tp-mm-megamenu__grid {
    gap: 12px;
  }

  .tp-mm-megamenu__list {
    gap: 2px;
  }
}

/* ================================
   LOADING STATES
   ================================ */

.tp-mm-megamenu--loading {
  pointer-events: none;
}

.tp-mm-megamenu--loading::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 24px;
  height: 24px;
  margin: -12px 0 0 -12px;
  border: 2px solid var(--gray-200);
  border-top: 2px solid var(--primary-color);
  border-radius: 50%;
  animation: tpMegamenuSpin 1s linear infinite;
}

@keyframes tpMegamenuSpin {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

/* ================================
   ACCESSIBILITY
   ================================ */

.tp-mm-megamenu[aria-hidden="true"] {
  display: none;
}

.tp-mm-megamenu__link:focus-visible {
  outline: 2px solid var(--primary-color);
  outline-offset: 2px;
}

/* High contrast mode */
@media (prefers-contrast: high) {
  .tp-mm-megamenu {
    border-width: 2px;
    border-color: var(--black);
  }

  .tp-mm-megamenu__link {
    border: 1px solid transparent;
  }

  .tp-mm-megamenu__link:hover,
  .tp-mm-megamenu__link:focus {
    border-color: var(--primary-color);
    background: var(--white);
  }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  .tp-mm-megamenu,
  .tp-mm-megamenu__list-item,
  .tp-mm-megamenu__link,
  .tp-mm-megamenu__bg-image,
  .tp-mm-megamenu__image-overlay {
    transition: none;
    animation: none;
  }

  .tp-mm-megamenu__list-item:hover {
    transform: none;
  }

  .tp-mm-megamenu__link:active {
    transform: none;
  }
}

/* ================================
   THEME INTEGRATION
   ================================ */

/* Ensure consistent theming with header */
.custom-header .tp-mm-megamenu {
  font-family: var(--font-primary);
}

.custom-header .tp-mm-megamenu__link {
  color: var(--text-primary);
}

.custom-header .tp-mm-megamenu__link:hover {
  color: var(--primary-color);
}

/* ================================
   UTILITIES
   ================================ */

.tp-mm-hidden {
  display: none !important;
}

.tp-mm-sr-only {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}
