/* =============================================================================
   MEGA MENU — Blogar Theme  v2
   css/mega-menu.css

   FIX 1: .mega-mobile-toggle + .mega-mobile-panel → base rule display:none
           (trước đây chỉ ẩn trong @media ≤1199px nên bị hiện trên desktop)

   FIX 2: Panel background full-width bằng negative left/right offset
           bù trừ padding của .axil-header (var --blogar-header-padding-x)

   Positioning:
     .header-inner { position: relative } → containing block
     Panel: left/right = calc(-1 * padding) → background to full viewport width
     .mega-panel-inner: padding = same value → content stays aligned

   Load order: sau header.css
   ============================================================================= */

/* =============================================================================
   FIX 1 — ẨN MOBILE ELEMENTS Ở MỌI KÍCH THƯỚC (BASE RULE)
   Override lại trong @media ≤1199px cho off-canvas.
   ============================================================================= */
.mega-mobile-toggle,
.mega-mobile-panel {
  display: none;
}

/* =============================================================================
   LI OVERRIDE
   Phải static để panel position relative to .header-inner
   ============================================================================= */
.mainmenu > li.blogar-has-mega {
  position: static;
}

.mainmenu > li.blogar-has-mega > ul.sub-menu {
  display: none !important;
}

/* =============================================================================
   CHEVRON
   ============================================================================= */
.mega-chevron {
  display: inline-block;
  vertical-align: middle;
  margin-left: 4px;
  margin-bottom: 1px;
  transition: transform 0.25s ease;
  flex-shrink: 0;
}

.mainmenu > li.blogar-has-mega.is-mega-open > a .mega-chevron {
  transform: rotate(180deg);
}

/* =============================================================================
   FIX 2 — PANEL: BACKGROUND FULL-WIDTH
   left/right âm bù trừ padding header → box-shadow + border-top full-width
   .mega-panel-inner có padding tương ứng để nội dung vẫn trong content space
   ============================================================================= */
.blogar-mega-panel {
  position: absolute;
  top: 100%;
  left: calc(-1 * var(--blogar-header-padding-x, 60px));
  right: calc(-1 * var(--blogar-header-padding-x, 60px));
  z-index: 200;

  background: var(--color-white, #fff);
  /* border-top: 3px solid var(--color-primary, #3858f6); */
  box-shadow: 0 16px 48px rgba(15, 23, 42, 0.12);

  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateY(6px);
  transition:
    opacity 0.22s ease,
    visibility 0.22s ease,
    transform 0.22s ease;
}

.mainmenu > li.blogar-has-mega.is-mega-open > .blogar-mega-panel {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: translateY(0);
}

/* =============================================================================
   PANEL INNER — padding bù lại, content nằm đúng trong content space
   ============================================================================= */
.mega-panel-inner {
  padding: 24px var(--blogar-header-padding-x, 60px);
  overflow: hidden;
}

/* =============================================================================
   TYPE 1 — sidebar tabs + post grid (mega-1)
   ============================================================================= */
.mega-panel-type-1 .mega-panel-inner {
  display: flex;
  align-items: flex-start;
  gap: 0;
  min-height: 220px;
}

/* Left sidebar */
.mega-cats-sidebar {
  flex: 0 0 180px;
  width: 180px;
  padding-right: 16px;
  border-right: 1px solid var(--color-lightest, #f0f2f5);
  display: flex;
  flex-direction: column;
  gap: 2px;
  align-self: stretch;
}

.mega-cat-tab {
  display: block;
  padding: 9px 14px;
  color: var(--color-body, #65676b);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  line-height: 1.3;
  border-radius: 6px;
  text-decoration: none;
  cursor: pointer;
  transition:
    color 0.2s ease,
    background-color 0.2s ease;
}

.mega-cat-tab:hover {
  color: var(--color-heading);
  background: var(--color-lightest, #f8f9fa);
}

.mega-cat-tab.is-active {
  color: var(--color-primary, #3858f6);
  background: rgba(56, 88, 246, 0.07);
}

/* Right post area */
.mega-posts-area {
  flex: 1;
  min-width: 0;
  padding-left: 24px;
}

.mega-posts-panel {
  display: none;
  grid-template-columns: repeat(4, 1fr);
  gap: 18px;
}

.mega-posts-panel.is-active {
  display: grid;
}

/* =============================================================================
   TYPE 2 — post grid only (mega-2)
   ============================================================================= */
.mega-posts-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 18px;
}

/* =============================================================================
   POST CARD (dùng chung)
   ============================================================================= */
.mega-post-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
}

.mega-post-thumb-link {
  position: relative;
  display: block;
  overflow: hidden;
  border-radius: var(--radius, 8px);
  aspect-ratio: 3 / 2;
  background: var(--color-lightest, #f0f2f5);
  flex-shrink: 0;
  text-decoration: none;
}

.mega-post-thumb-link img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  transition: transform 0.4s ease;
}

.mega-post-card:hover .mega-post-thumb-link img {
  transform: scale(1.06);
}

.mega-post-cat-badge {
  position: absolute;
  top: 8px;
  left: 8px;
  z-index: 1;
  display: inline-block;
  padding: 2px 8px;
  background: var(--color-primary, #3858f6);
  color: #fff;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  border-radius: 3px;
  line-height: 1.7;
  white-space: nowrap;
  max-width: calc(100% - 16px);
  overflow: hidden;
  text-overflow: ellipsis;
}

.mega-post-body {
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-width: 0;
}

.mega-post-title {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  line-height: 1.45;
  color: var(--color-heading);
  display: -webkit-box;
  overflow: hidden;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.mega-post-title a {
  color: inherit;
  text-decoration: none;
  transition: color 0.2s ease;
}

.mega-post-title a:hover {
  color: var(--color-primary, #3858f6);
}

.mega-post-date {
  display: block;
  font-size: 11px;
  color: var(--color-midgray);
  line-height: 1.2;
}

/* =============================================================================
   DESKTOP-SM: 1200–1599px
   --blogar-header-padding-x = 30px (từ header.css)
   Panel tự tính left/right từ biến CSS → không cần override.
   ============================================================================= */
@media only screen and (min-width: 1200px) and (max-width: 1599px) {
  .mega-cats-sidebar {
    flex: 0 0 155px;
    width: 155px;
    padding-right: 12px;
  }

  .mega-posts-area {
    padding-left: 16px;
  }

  .mega-posts-panel,
  .mega-posts-grid {
    gap: 12px;
  }

  .mega-cat-tab {
    padding: 8px 10px;
    font-size: 10px;
  }

  .mega-post-title {
    font-size: 12px;
  }
}

/* =============================================================================
   TABLET + MOBILE: ≤ 1199px
   Desktop panel ẩn, mobile accordion hiện trong off-canvas.
   ============================================================================= */
@media only screen and (max-width: 1199px) {
  /* Ẩn desktop panel trong off-canvas */
  .mainmenu-item .blogar-has-mega .blogar-mega-panel {
    display: none !important;
  }

  /* Ẩn desktop chevron trong off-canvas */
  .mainmenu-item .blogar-has-mega > a .mega-chevron {
    display: none;
  }

  /* Hiện mobile toggle trong off-canvas (override base display:none) */
  .mainmenu-item li.blogar-has-mega .mega-mobile-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 26px;
    height: 26px;
    padding: 0;
    color: var(--color-midgray);
    background: var(--color-lightest, #f0f2f5);
    border: 0;
    border-radius: 4px;
    cursor: pointer;
    margin-left: 8px;
    transition:
      color 0.2s ease,
      background-color 0.2s ease;
  }

  .mainmenu-item li.blogar-has-mega .mega-mobile-toggle:hover {
    color: var(--color-primary, #3858f6);
    background: rgba(56, 88, 246, 0.1);
  }

  .mainmenu-item li.blogar-has-mega .mega-mobile-toggle svg {
    transition: transform 0.25s ease;
  }

  .mainmenu-item
    li.blogar-has-mega
    .mega-mobile-toggle[aria-expanded="true"]
    svg {
    transform: rotate(180deg);
  }

  /* Hiện mobile panel khi is-open (override base display:none) */
  .mainmenu-item li.blogar-has-mega .mega-mobile-panel.is-open {
    display: flex;
    flex-direction: column;
  }

  /* Li chứa mega: flex để toggle button inline với link text */
  .mainmenu-item li.blogar-has-mega {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    padding: 12px 0;
    border-bottom: 1px solid var(--color-lightest, #f0f2f5);
  }

  .mainmenu-item li.blogar-has-mega > a {
    flex: 1 1 auto;
    color: var(--color-gray);
    font-size: 16px;
    font-weight: 500;
    line-height: 1.5;
    transition: color 0.2s ease;
  }

  .mainmenu-item li.blogar-has-mega > a:hover,
  .mainmenu-item li.blogar-has-mega > a.current-menu-item {
    color: var(--color-primary, #3858f6);
  }

  /* Mobile panel: wrap xuống dòng mới, full width */
  .mainmenu-item li.blogar-has-mega .mega-mobile-panel {
    flex: 0 0 100%;
    width: 100%;
  }

  /* Link items trong mobile panel */
  .mega-mobile-link {
    display: block;
    padding: 8px 0 8px 16px;
    color: var(--color-midgray);
    font-size: 13px;
    font-weight: 500;
    line-height: 1.4;
    text-decoration: none;
    border-top: 1px solid var(--color-lightest, #f0f2f5);
    transition: color 0.2s ease;
  }

  .mega-mobile-link:hover {
    color: var(--color-primary, #3858f6);
  }

  .mega-mobile-link.mega-mobile-all {
    color: var(--color-primary, #3858f6);
    font-weight: 700;
  }
}

/* =============================================================================
   MOBILE: ≤ 767px
   ============================================================================= */
@media only screen and (max-width: 767px) {
  .mainmenu-item li.blogar-has-mega {
    padding: 10px 0;
  }

  .mainmenu-item li.blogar-has-mega > a {
    font-size: 15px;
  }

  .mega-mobile-link {
    font-size: 12px;
    padding: 7px 0 7px 12px;
  }
}
