/* Mega Menu - complete styles (plugin CSS output disabled) */

/* Reset base */
#mega-menu-wrap-primary,
#mega-menu-wrap-primary *,
#mega-menu-wrap-primary *::before,
#mega-menu-wrap-primary *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  list-style: none;
}

#mega-menu-wrap-primary {
  /*position: relative;*/
  font-family: inherit;
  font-size: 1rem;
  line-height: 1.6;

  /* Mobile toggle: hidden on desktop */
  .mega-menu-toggle {
    display: none;
  }

  /* Top-level menu bar */
  #mega-menu-primary {
    display: flex;
    align-items: baseline;
    gap: 0.5rem;

    .mega-menu-link {
      text-decoration: none;
    }


    /* Top-level items */
    & > li.mega-menu-item {

      & > a.mega-menu-link {
        display: inline-flex;
        align-items: center;
        gap: 0.25rem;
        padding: 0.5rem 0.75rem;
        color: var(--wp--preset--color--contrast, #0b0b0c);
        text-decoration: none;
        font-size: var(--wp--preset--font-size--medium);
        white-space: nowrap;
        transition: all .3s ease-in-out;

        &:hover,
        &[aria-expanded="true"] {
          /*color: #0b0b0c;*/

          .mega-menu-link-text {
            text-decoration: underline;
          }
        }
      }

      /* Dropdown indicator arrow */
      .mega-indicator {
        display: inline-block;
        margin-left: 0.15rem;
        font-size: 0.7em;
        rotate: -90deg;
        transition: rotate 0.2s;
        pointer-events: none;
        text-decoration: none;

        &::after {
          content: "\2193";
        }
      }

      /* Kontakt pill button */
      &.mega-menu-btn > a.mega-menu-link,
      &.mega-menu-kontakt > a.mega-menu-link {
        background-color: var(--wp--preset--color--accent-1, #00205b);
        color: #fff;
        border-radius: 9999px;
        padding: 0.4rem 1.25rem;

        &:hover {
          opacity: 0.85;
        }
      }

      /* --- Mega dropdown panel (grid type) --- */
      &.mega-menu-grid > ul.mega-sub-menu {
        display: none;
        position: absolute;
        left: 50%;
        top: 100%;
        width: 100vw;
        transform: translateX(-50%);
        z-index: 999;
        background: #fff;
        /*border-top: 1px solid #eee;*/
        box-shadow: 0 20px 5px 10px rgba(0, 0, 0, 0.08);
        padding: 2.5rem 0;

        a {

          .mega-menu-link-text,
          span {
            font-weight: 300;
            /*font-weight: inherit;*/
          }
        }

        /* Grid row */
        li.mega-menu-row {
          max-width: var(--wp--style--global--wide-size, 1340px);
          margin-inline: auto;

          @media (min-width: 768px) {
            padding-inline: 2rem;
          }

          @media (min-width: 1400px) {

            padding-inline: 0;
          }
        }

        li.mega-menu-row > ul.mega-sub-menu {
          display: grid;
          grid-template-columns: repeat(auto-fit, minmax(0, 1fr));
          gap: 3rem;
        }

        /* Nested sub-menu spacing */
        ul.mega-sub-menu ul.mega-sub-menu {
          margin-top: 1rem;
        }

        /* Columns */
        li.mega-menu-column + li.mega-menu-column {
          border-left: 1px solid #eee;
          padding-left: 3rem;
        }

        li.mega-menu-column {
          & > ul.mega-sub-menu {
            display: grid;
            grid-template-columns: 1fr;
            gap: 1rem;

            @media (min-width: 769px) {
              grid-template-columns: repeat(auto-fit, minmax(0, 1fr));
            }

            @media (min-width: 769px) {
              & > li + li {
                border-left: 1px solid #eee;
                padding-left: 3rem;
              }
            }
          }

          /* Column heading */
          li.mega-menu-item-has-children > a.mega-menu-link {
            font-weight: 500;
            color: var(--wp--preset--color--contrast, #0b0b0c);
            padding: 0 0 0.75rem 0;
            pointer-events: none;
            font-size: var(--wp--preset--font-size--small);

            @media (min-width: 769px) {
              font-size: var(--wp--preset--font-size--medium);
            }

            span,
            .mega-menu-link-text {
              font-weight: inherit;
            }

            .mega-indicator {
              display: none;
            }
          }

          /* Column sub-items */
          li.mega-menu-item-has-children > ul.mega-sub-menu {
            display: block;

            li.mega-menu-item {
              a.mega-menu-link {
                display: inline-flex;
                align-items: center;
                padding: 0.3rem 0 0.3rem 1.25rem;
                color: var(--wp--preset--color--contrast, #0b0b0c);
                text-decoration: none;
                position: relative;

                font-size: var(--wp--preset--font-size--small);

                @media (min-width: 769px) {
                  font-size: var(--wp--preset--font-size--medium);
                }

                &::before {
                  content: "\2192";
                  position: absolute;
                  left: 0;
                  font-size: 16px;
                  color: var(--wp--preset--color--contrast, #0b0b0c);
                }

                &:hover {
                  text-decoration: underline;
                }
              }
            }
          }
        }

        /* Widget block titles (e.g. "Siste nytt") */
        h4.mega-block-title {
          font-weight: 500;
          font-size: var(--wp--preset--font-size--small);
          color: var(--wp--preset--color--contrast, #0b0b0c);
          padding-bottom: 0.75rem;

          @media (min-width: 769px) {
            font-size: var(--wp--preset--font-size--medium);
          }
        }

        /* Widget list items (e.g. recent posts) */
        .widget_recent_entries ul li {
          padding: 0.3rem 0 0.3rem 1.25rem;
          position: relative;

          &::before {
            content: "\2192";
            position: absolute;
            left: 0;
          }

          a {
            color: var(--wp--preset--color--contrast, #0b0b0c);
            text-decoration: none;
            font-size: var(--wp--preset--font-size--medium);

            &:hover {
              text-decoration: underline;
            }
          }
        }

        /* Recent posts with featured image widget */
        .metier-recent-posts {
          display: flex;
          flex-direction: column;
          gap: 1rem;
          list-style: none;
          padding: 1rem 0 0 0;
          margin: 0;

          li {
            display: flex;
            align-items: center;
            gap: 0.75rem;

            img {
              width: 60px;
              height: 60px;
              object-fit: cover;
              border-radius: 4px;
              flex-shrink: 0;
            }

            a {
              color: var(--wp--preset--color--contrast, #0b0b0c);
              text-decoration: none;
              font-size: var(--wp--preset--font-size--small);

              @media (min-width: 769px) {
                font-size: var(--wp--preset--font-size--medium);
              }

              &:hover {
                text-decoration: underline;
              }
            }
          }
        }
      }

      /* Rotate indicator when toggled open (desktop only) */
      @media (min-width: 769px) {
        &.mega-toggle-on > a.mega-menu-link .mega-indicator {
          rotate: 0deg;
        }
      }

      /* Show dropdown when toggled open (all screens) */
      &.mega-menu-grid.mega-toggle-on > ul.mega-sub-menu {
        display: block;
      }

      /* --- Flyout dropdown (simple sub-menus) --- */
      &.mega-menu-flyout {
        position: relative;
      }

      &.mega-menu-flyout > ul.mega-sub-menu {
        display: none;
        position: absolute;
        left: 0;
        top: 100%;
        z-index: 999;
        background: #fff;
        box-shadow: 0 8px 24px rgba(0, 0, 0, 0.08);
        padding: 0.5rem 0;
        min-width: 200px;

        li.mega-menu-item a.mega-menu-link {
          display: block;
          padding: 0.4rem 1.25rem;
          color: var(--wp--preset--color--contrast, #0b0b0c);
          text-decoration: none;
          font-size: var(--wp--preset--font-size--medium);
          white-space: nowrap;

          &:hover {
            background-color: #f5f5f5;
          }
        }
      }


      &.mega-menu-flyout.mega-toggle-on > ul.mega-sub-menu {
        display: block;
      }
    }
  }

  /* Close button: hidden on desktop */
  button.mega-close,
  button.metier-mobile-close {
    display: none;
  }
}

/* Mobile: slide-in drawer from right */
@media (max-width: 768px) {
  #mega-menu-wrap-primary {
    .mega-menu-toggle {
      display: flex;
      align-items: center;
    }

    .mega-toggle-animated {
      background: none;
      border: none;
      cursor: pointer;
      padding: 0.5rem;

      .mega-toggle-animated-box {
        display: block;
        width: 24px;
        height: 18px;
        position: relative;
      }

      .mega-toggle-animated-inner,
      .mega-toggle-animated-inner::before,
      .mega-toggle-animated-inner::after {
        display: block;
        width: 24px;
        height: 2px;
        background-color: var(--wp--preset--color--contrast, #0b0b0c);
        position: absolute;
        content: "";
      }

      .mega-toggle-animated-inner {
        top: 50%;
        transform: translateY(-50%);

        &::before { top: -7px; }
        &::after { bottom: -7px; }
      }
    }

    button.metier-mobile-close {
      display: flex;
      align-self: flex-end;
      align-items: center;
      justify-content: center;
      background: none;
      border: none;
      cursor: pointer;
      padding: 0.25rem;
      font-size: 1.5rem;
      line-height: 1;
      color: var(--wp--preset--color--contrast, #0b0b0c);
      margin-bottom: 1rem;
    }

    #mega-menu-primary {
      position: fixed;
      top: 0;
      right: 0;
      bottom: 0;
      width: 85vw;
      max-width: 400px;
      background: #fff;
      box-shadow: -4px 0 24px rgba(0, 0, 0, 0.12);
      z-index: 9999;
      flex-direction: column;
      gap: 0;
      padding: 1.5rem;
      overflow-y: auto;
      transform: translateX(100%);
      transition: transform 0.3s ease;
      display: flex;

      & > li.mega-menu-item {
        border-bottom: 1px solid #f0f0f0;
        width: 100%;

        & > a.mega-menu-link {
          display: flex;
          justify-content: space-between;
          align-items: center;
          padding: 0.85rem 0;

          font-size: var(--wp--preset--font-size--medium);
          color: var(--wp--preset--color--contrast, #0b0b0c);
          text-decoration: none;
        }

        .mega-indicator {
          transition: rotate 0.25s ease;
        }

        &.metier-open > a .mega-indicator {
          rotate: 0deg;
        }

        /* Kontakt pill on mobile */
        &.mega-menu-kontakt {
          border-bottom: none;

          & > a.mega-menu-link {
            background-color: var(--wp--preset--color--accent-1, #00205b);
            color: #fff;
            border-radius: 9999px;
            padding: 0.6rem 1.25rem;
            margin: 1rem 0;
            justify-content: center;
          }
        }



        /* No underline on any menu links */
        ul.mega-sub-menu a,
        ul.mega-sub-menu a:hover,
        & > a.mega-menu-link,
        & > a.mega-menu-link:hover {
          text-decoration: none;
        }

        /* Sub-menus: accordion style */
        &.mega-menu-grid > ul.mega-sub-menu,
        &.mega-menu-flyout > ul.mega-sub-menu {
          display: none;
          position: static;
          box-shadow: none;
          min-width: 0;
          padding: 0 0;
          width: auto;
          transform: none;
          left: auto;

          @media (min-width: 769px) {
            padding: 0.25rem 0 0.75rem 1rem;
          }
        }

        &.mega-menu-grid.metier-open > ul.mega-sub-menu,
        &.mega-menu-flyout.metier-open > ul.mega-sub-menu {
          padding: 0 0;
          display: block;

          @media (min-width: 1024px) {
            padding: 1rem 0;
          }
        }

        /* Sub-menu grid columns stack on mobile */
        &.mega-menu-grid > ul.mega-sub-menu li.mega-menu-row > ul.mega-sub-menu {
          display: flex;
          flex-direction: column;
          gap: 1rem;
        }

        /* Remove column borders on mobile */
        &.mega-menu-grid > ul.mega-sub-menu li.mega-menu-column + li.mega-menu-column {
          border-left: none;
          padding-left: 0;
          border-top: 1px solid #eee;
          padding-top: 1rem;
        }
      }
    }
  }

  /* Dim overlay behind drawer */
  body.mega-menu-primary-mobile-open::before {
    content: "";
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 9998;
  }

  /* Slide drawer in when open */
  body.mega-menu-primary-mobile-open #mega-menu-wrap-primary #mega-menu-primary {
    transform: translateX(0);
  }

  /* Restore mini cart icon size */
  body .wc-block-mini-cart__button .wc-block-mini-cart__icon {
    width: 30px;
    height: 30px;
  }
}

#mega-menu-wrap-primary a:focus {
  outline: none;
}

/* Sub-menu link swipe on hover — excludes top-level links and pointer-events:none headings */
@media (min-width: 769px) {
  #mega-menu-wrap-primary ul.mega-sub-menu a.mega-menu-link {
    transition: transform 0.3s ease-in-out;
  }

  #mega-menu-wrap-primary ul.mega-sub-menu a.mega-menu-link:hover {
    transform: translateX(16px);
  }
}
