/* ============================================================
   Mega Menu — Meskavan (Gutenberg Navigation block)
   ------------------------------------------------------------
   Turns any submenu of a header nav item into a full-width row
   of brand cards on hover. Desktop only (>=1024px); mobile keeps
   the native Gutenberg accordion untouched.

   Self-contained & transferable: copy this file, enqueue it, and
   (optionally) add the excerpt filter in functions.php. All
   selectors are scoped under .site-header so nothing else on the
   site is affected.
   ============================================================ */

:root { --mega-menu-top: 101px; } /* JS overrides with real header bottom */

.site-header { --msk-dark: #0B383C; --msk-copper: #BA6D51; --msk-light: #FBF6F5; }

/* Description text is injected into every linked item but only ever
   shown inside the desktop mega cards — hide it everywhere by default. */
.site-header .wp-block-navigation .msk-mega-desc { display: none; }

@media (min-width: 1024px) {

  /* ── Parent label affordance on hover ─────────────────────── */
  .site-header .wp-block-navigation .has-child:hover    > .wp-block-navigation-item__content .wp-block-navigation-item__label,
  .site-header .wp-block-navigation .has-child:focus-within > .wp-block-navigation-item__content .wp-block-navigation-item__label {
    text-decoration: underline;
    text-decoration-color: var(--msk-copper);
    text-decoration-thickness: 2px;
    text-underline-offset: 6px;
  }

  /* Chevron flips when the panel is open */
  .site-header .wp-block-navigation .has-child > .wp-block-navigation__submenu-icon {
    transition: transform .3s ease;
  }
  .site-header .wp-block-navigation .has-child:hover    > .wp-block-navigation__submenu-icon,
  .site-header .wp-block-navigation .has-child:focus-within > .wp-block-navigation__submenu-icon {
    transform: rotate(180deg);
  }

  /* ── The mega panel (submenu container) ───────────────────── */
  .site-header .wp-block-navigation .has-child > .wp-block-navigation__submenu-container {
    /* break out of the narrow dropdown into a centered, header-width
       row pinned just under the sticky header */
    position: fixed !important;
    /* pinned to the live header-pill geometry (set by mega-menu.js) so it stays
       aligned on any monitor width / aspect ratio */
    top: calc(var(--mega-menu-top, 117px) - 1px);   /* -1px welds onto the pill */
    left: var(--mega-menu-left, 0) !important;
    right: auto !important;
    width: var(--mega-menu-width, 100%) !important;
    max-width: none !important;
    margin: 0 !important;
    padding: 22px 26px 26px;

    /* layout — grid (not flex): a fixed-position flex row collapses its own
       height to the padding box; grid reliably sizes to the tallest card and
       stretches every card to match (equal-height row, equal-width columns) */
    display: grid !important;
    /* auto-fit: any number of items lays out cleanly — few stretch to fill,
       many wrap to a second row. No JS, no per-menu tuning. */
    grid-template-columns: repeat(auto-fit, minmax(min(240px, 100%), 1fr));
    align-items: stretch;
    gap: 16px;

    /* strip the native dropdown chrome, then dress it as an attached panel */
    min-width: 0;
    height: auto !important;       /* core pins a small fixed height… */
    max-height: none !important;
    overflow: visible !important;  /* …and clips with overflow:hidden — undo both */
    border: 0;
    border-radius: 0 0 16px 16px !important;  /* square top (welded to header), rounded bottom */
    background: #F1E9E2 !important;           /* a touch darker than the page; beats per-item block bg */
    box-shadow: 0 22px 44px rgba(11,56,60,0.12);

    /* hidden state — fade only (no translate: a stray core transform left a gap) */
    visibility: hidden;
    opacity: 0;
    pointer-events: none;
    transition: opacity .24s ease, visibility 0s linear .24s;
    z-index: 999;
  }

  .site-header .wp-block-navigation .has-child:hover    > .wp-block-navigation__submenu-container,
  .site-header .wp-block-navigation .has-child:focus-within > .wp-block-navigation__submenu-container {
    visibility: visible;
    opacity: 1;
    pointer-events: auto;
    transition: opacity .24s ease;
  }

  /* Weld the header pill to the open panel: flatten the pill's bottom corners
     while any submenu is open, so header + panel read as one piece. */
  .site-header .msk-mega-host { transition: border-radius .2s ease; }
  .site-header .msk-mega-host.msk-mega-open {
    border-bottom-left-radius: 0 !important;
    border-bottom-right-radius: 0 !important;
  }

  /* Invisible bridge so the cursor can travel from label → cards
     without the panel collapsing in the visual gap. */
  .site-header .wp-block-navigation .has-child > .wp-block-navigation__submenu-container::before {
    content: '';
    position: absolute;
    top: -40px; left: 0; right: 0;   /* spans the ~28px gap between menu row and panel */
    height: 44px;
  }

  /* ── Each submenu item → a card ───────────────────────────── */
  .site-header .wp-block-navigation .has-child > .wp-block-navigation__submenu-container > .wp-block-navigation-item {
    display: block !important;  /* core makes the item a flex row w/ align-items:center,
                                   which clips the tall card — block lets it size to content */
    flex: 1 1 0 !important;
    width: auto !important;
    height: auto !important;    /* core sets an explicit ~18px height; clear it */
    min-height: 156px !important;
    min-width: 0;
    margin: 0;
    position: relative;
    background: #FFFFFF;
    border: 1px solid rgba(11,56,60,0.08);
    border-radius: 14px;
    overflow: hidden;
    transition: border-color .2s ease;
  }
  .site-header .wp-block-navigation .has-child > .wp-block-navigation__submenu-container > .wp-block-navigation-item:hover {
    border-color: var(--msk-copper);   /* copper stroke only — no lift, no shadow */
  }

  /* The link fills the whole card */
  .site-header .wp-block-navigation .has-child > .wp-block-navigation__submenu-container > .wp-block-navigation-item > .wp-block-navigation-item__content {
    display: flex;
    flex-direction: column;
    gap: 10px;
    align-items: flex-start;
    text-align: start;
    padding: 22px 24px 66px !important;   /* bottom room for the corner arrow */
    min-height: 156px;
    width: 100%;
    height: 100%;
    color: var(--msk-dark);
    text-decoration: none !important;
  }

  /* Title */
  .site-header .wp-block-navigation .has-child > .wp-block-navigation__submenu-container .wp-block-navigation-item__label {
    font-size: 1.15rem;
    font-weight: 700;
    line-height: 1.5;
    color: var(--msk-dark);
  }

  /* Description (only inside the cards) */
  .site-header .wp-block-navigation .wp-block-navigation__submenu-container .msk-mega-desc {
    display: block;
    font-size: 0.86rem;
    font-weight: 400;
    line-height: 1.85;
    color: rgba(11,56,60,0.62);
  }

  /* Corner arrow button — bottom-left in RTL (inset-inline-end) */
  .site-header .wp-block-navigation .has-child > .wp-block-navigation__submenu-container > .wp-block-navigation-item::after {
    content: '';
    position: absolute;
    inset-block-end: 18px;
    inset-inline-end: 22px;
    width: 40px;
    height: 40px;
    border-radius: 11px;
    background-color: var(--msk-copper);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23ffffff' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M16 16L8 8'/%3E%3Cpath d='M8 14V8h6'/%3E%3C/svg%3E");
    background-position: center;
    background-size: 20px 20px;
    background-repeat: no-repeat;
    transition: background-color .25s ease, transform .25s ease;
    pointer-events: none;
  }

  /* ══════════════════════════════════════════════════════════════
     BLOG mega — only the item flagged .msk-mega--blog (the "بلاگ"
     parent). Categories on the right, latest posts on the left.
     Overrides the card grid above for this one panel.
     ══════════════════════════════════════════════════════════════ */
  .site-header .wp-block-navigation .has-child > .msk-mega--blog {
    display: block !important;
  }
  /* hide the placeholder menu items — content is injected dynamically.
     Must out-specify the card rule (.…submenu-container > .…navigation-item),
     so match the same depth via the original items' own class. */
  .site-header .wp-block-navigation .has-child > .msk-mega--blog > .wp-block-navigation-item {
    display: none !important;
  }
  .site-header .msk-mega--blog > li.msk-bm-li {
    display: block !important;
    min-height: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
    background: transparent !important;
    border: 0 !important;
    overflow: visible !important;
  }
  .site-header .msk-bm {
    display: grid;
    grid-template-columns: 264px 1fr;  /* RTL: first track (cats) sits on the right */
    gap: 30px;
    align-items: stretch;   /* both columns equal height → posts match the cats list */
  }
  .site-header .msk-bm__h {
    display: block;
    font-size: 0.78rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    color: var(--msk-copper);
    margin: 0 0 14px;
    padding-bottom: 10px;
    border-bottom: 1px solid rgba(11,56,60,0.12);
  }

  /* Categories (right) — plain names, no counts */
  .site-header .msk-bm__cats { display: flex; flex-direction: column; gap: 2px; }
  .site-header .msk-bm__cat {
    display: block; padding: 10px 13px; border-radius: 10px;
    text-decoration: none; color: var(--msk-dark);
    font-size: 0.95rem; font-weight: 500;
    transition: background-color .2s ease, color .2s ease;
  }
  .site-header .msk-bm__cat:hover { background: #FFFFFF; color: var(--msk-copper); }
  .site-header .msk-bm__all {
    margin-top: 10px; padding: 10px 13px;
    font-size: 0.86rem; font-weight: 700; color: var(--msk-copper);
    text-decoration: none;
  }
  .site-header .msk-bm__all:hover { text-decoration: underline; text-underline-offset: 4px; }

  /* Latest posts (left) — featured-style cards: full image + overlaid meta/title,
     like the "مقاله ویژه" on the blog page. 5 across, sized down to fit. */
  .site-header .msk-bm__posts { display: flex; flex-direction: column; }
  .site-header .msk-bm__posts-grid {
    flex: 1;                       /* fill the column so cards reach the cats list's bottom */
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(155px, 100%), 1fr));
    grid-auto-rows: 1fr;           /* rows stretch to fill the height */
    gap: 14px;
  }
  .site-header .msk-bm__post {
    position: relative;
    display: block;
    min-height: 200px;     /* floor; stretches taller to match the categories column */
    height: 100%;
    border-radius: 14px;
    overflow: hidden;
    text-decoration: none;
    background-size: cover;
    background-position: center;
    background-color: #0B383C;
    border: 1px solid rgba(11,56,60,0.08);
    transition: border-color .2s ease;
  }
  .site-header .msk-bm__post--ph {
    background: linear-gradient(140deg, #0B383C 0%, #041414 60%, #062824 100%);
  }
  /* warm overlay (not green) — fits the light cream panel + keeps text legible */
  .site-header .msk-bm__post::after {
    content: '';
    position: absolute; inset: 0;
    background: linear-gradient(to top,
      rgba(40,23,15,0.92) 0%, rgba(40,23,15,0.42) 42%, rgba(40,23,15,0) 72%);
  }
  /* hover: lift + vivid copper stroke, NO shadow */
  .site-header .msk-bm__post:hover {
    border-color: #BA6D51;   /* copper stroke only — no lift, no shadow */
  }
  .site-header .msk-bm__post-body {
    position: absolute; inset-inline: 0; inset-block-end: 0; z-index: 1;
    padding: 13px 14px;
    display: flex; flex-direction: column; gap: 7px;
  }
  .site-header .msk-bm__post-meta { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
  .site-header .msk-bm__post-cat {
    font-size: 0.64rem; letter-spacing: 0.02em;
    background: rgba(186,109,81,0.92); color: #FFFFFF;
    padding: 3px 9px; border-radius: 100px;
  }
  .site-header .msk-bm__post-date { font-size: 0.66rem; color: rgba(255,255,255,0.72); }
  .site-header .msk-bm__post-title {
    font-size: 0.82rem; font-weight: 700; color: #FFFFFF; line-height: 1.5;
    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  }

}
