/**
 * @file
 * MLT Modern — Header (logo strip + accreditations) and primary navigation
 * (main menu + mobile burger).
 *
 * Two regions covered in this file:
 *
 *   .mlt-region--header        — Logo strip + accreditation banner.
 *                                White background, contained width.
 *
 *   .mlt-region--primary-nav   — Main navigation (Drupal core block) +
 *                                mobile burger toggle. Full-width blue
 *                                band on desktop, single burger button
 *                                on mobile.
 *
 * Block placements expected (via Structure → Block layout):
 *
 *   Header region:
 *     - MLT Modern — Header Logo Strip (custom HTML block; markup below)
 *
 *   Primary navigation region:
 *     - Main navigation (Drupal core system_menu_block:main)
 *     - MLT Modern — Mobile burger toggle (custom HTML block; markup below)
 *
 *
 * HEADER LOGO STRIP — custom HTML block markup (Full HTML format):
 *
 *   <div class="mlt-header">
 *     <div class="mlt-header__inner">
 *       <a href="/" class="mlt-header__logo" aria-label="Home">
 *         <img src="/sites/default/files/jjb-logo-lrage-blue-web_0_0.png"
 *              alt="JJB Electrical Ltd">
 *       </a>
 *       <div class="mlt-header__accreds">
 *         <img src="/sites/default/files/inline-images/accredititions%20banner.png"
 *              alt="NAPIT Part P, Which? Trusted Trader, TrustMark,
 *                   Hertfordshire Trading Standards approved"
 *              loading="lazy">
 *       </div>
 *     </div>
 *   </div>
 *
 * BURGER MENU — custom HTML block markup (Full HTML format):
 *
 *   <button type="button" class="mlt-burger"
 *           aria-controls="block-mlt-modern-mainnavigation"
 *           aria-expanded="false"
 *           aria-label="Toggle navigation menu">
 *     <span class="mlt-burger__bars"></span>
 *   </button>
 *
 * Adjust `aria-controls` to match the actual ID of the main navigation
 * block as it renders in your installation (check view-source).
 */

/* =======================================================================
 * HEADER REGION — logo strip + accreditations
 * ======================================================================= */

.mlt-header {
  background: #fff;
  padding: 20px 0;
  border-bottom: 1px solid var(--mlt-border);
}

.mlt-header__inner {
  max-width: var(--mlt-container-max);
  margin: 0 auto;
  padding: 0 var(--mlt-container-pad);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 20px;
}

.mlt-header__logo {
  display: inline-flex;
  align-items: center;
  text-decoration: none;
}

.mlt-header__logo img {
  max-height: 80px;
  width: auto;
  display: block;
}

.mlt-header__accreds img {
  max-height: 60px;
  max-width: 100%;
  width: auto;
  height: auto;
  display: block;
}

/* =======================================================================
 * PRIMARY NAVIGATION REGION — main menu + mobile burger
 *
 * Drupal core's system_menu_block renders the main menu as plain semantic
 * HTML — no extra classes, just <nav><ul><li><a>. We target the elements
 * directly within the primary_nav region.
 *
 * Markup (Drupal core menu block, depth = unlimited):
 *   <div class="mlt-region mlt-region--primary-nav">
 *     <nav role="navigation" id="block-mlt-modern-mainnavigation">
 *       <h2 class="visually-hidden">Main navigation</h2>
 *       <ul>
 *         <li><a href="/">Home</a></li>
 *         <li>
 *           <a href="/services">Services/Pricing</a>
 *           <ul>  <!-- only present if menu depth > 1 -->
 *             <li><a href="/service/...">EV Chargers</a></li>
 *             ...
 *           </ul>
 *         </li>
 *       </ul>
 *     </nav>
 *   </div>
 *
 * For dropdowns to appear in the HTML, the menu block must be configured
 * with "Number of levels to display" > 1 in its block settings.
 * ======================================================================= */

/* Anchor for the burger's absolute position. Stable container — won't
 * move if blocks are added to the header above. */
.mlt-region--primary-nav {
  position: relative;
}

/* The whole nav block — full-width blue strip. */
.mlt-region--primary-nav nav {
  background: var(--mlt-primary);
  width: 100%;
}

/* Constrain the menu's inner content to container width. */
.mlt-region--primary-nav nav > ul {
  max-width: var(--mlt-container-max);
  margin: 0 auto;
  padding: 0 var(--mlt-container-pad);
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  list-style: none;
}

/* Top-level menu items. position: relative anchors the dropdown ul. */
.mlt-region--primary-nav nav > ul > li {
  position: relative;
  list-style: none;
  margin: 0;
  padding: 0;
}

/* Top-level links. */
.mlt-region--primary-nav nav > ul > li > a {
  display: block;
  color: #fff;
  text-decoration: none;
  padding: 16px 18px;
  font-weight: 600;
  font-size: 15px;
  line-height: 1;
  transition: background 0.15s, color 0.15s;
}

.mlt-region--primary-nav nav > ul > li > a:hover,
.mlt-region--primary-nav nav > ul > li > a:focus,
.mlt-region--primary-nav nav > ul > li > a.is-active {
  background: var(--mlt-primary-dark);
  color: #fff;
  text-decoration: none;
}

/* The "current page" link variant (Drupal core adds .is-active). */
.mlt-region--primary-nav nav a.is-active {
  color: var(--mlt-accent);
}

/* ----- Dropdown submenus -----
 * Pure-CSS dropdown: hidden by default, revealed on parent :hover or :focus-within.
 * Positioned absolutely below the parent li.
 *
 * focus-within keeps the dropdown open while keyboard users tab through
 * items inside it.
 */
.mlt-region--primary-nav nav > ul > li > ul {
  position: absolute;
  top: 100%;
  left: 0;
  display: none;
  background: var(--mlt-primary-dark);
  list-style: none;
  margin: 0;
  padding: 6px 0;
  min-width: 220px;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.18);
  border-radius: 0 0 var(--mlt-radius-sm) var(--mlt-radius-sm);
  z-index: 100;
}

.mlt-region--primary-nav nav > ul > li:hover > ul,
.mlt-region--primary-nav nav > ul > li:focus-within > ul {
  display: block;
}

/* Dropdown items. */
.mlt-region--primary-nav nav ul ul li {
  list-style: none;
  margin: 0;
  padding: 0;
}

.mlt-region--primary-nav nav ul ul li a {
  display: block;
  color: #fff;
  text-decoration: none;
  padding: 10px 18px;
  font-weight: 500;
  font-size: 14px;
  line-height: 1.3;
  background: transparent;
  transition: background 0.15s, color 0.15s;
}

.mlt-region--primary-nav nav ul ul li a:hover,
.mlt-region--primary-nav nav ul ul li a:focus,
.mlt-region--primary-nav nav ul ul li a.is-active {
  background: var(--mlt-primary);
  color: var(--mlt-accent);
}

/* Dropdown indicator chevron — added via CSS on items that have a child ul.
 * Uses :has() to detect the presence of a nested ul. Supported in all
 * modern browsers (Chrome/Edge 105+, Safari 15.4+, Firefox 121+). */
.mlt-region--primary-nav nav > ul > li:has(> ul) > a::after {
  content: " ▾";
  font-size: 10px;
  opacity: 0.7;
  margin-left: 4px;
}

/* =======================================================================
 * BURGER MENU — visible only on mobile (< 900px). Placed in the
 * primary_nav region as its own custom HTML block.
 *
 * The bars are made of one element with two pseudo-elements (::before
 * and ::after) so we get three lines with one DOM node.
 *
 * Hidden on desktop. JS in js/menu-toggle.js handles the click → toggles
 * .mlt-nav--open on the nav element.
 * ======================================================================= */

.mlt-burger {
  display: none; /* shown on mobile via @media below */
  width: 44px;
  height: 44px;
  padding: 0;
  background: transparent;
  border: none;
  cursor: pointer;
  position: relative;
  align-items: center;
  justify-content: center;
  /* Centre the burger inside its block wrapper on mobile when shown. */
  margin: 0 auto;
}

.mlt-burger:focus-visible {
  outline: 2px solid var(--mlt-accent);
  outline-offset: 2px;
}

.mlt-burger__bars,
.mlt-burger__bars::before,
.mlt-burger__bars::after {
  display: block;
  position: absolute;
  left: 10px;
  right: 10px;
  height: 3px;
  background: var(--mlt-primary);
  border-radius: 2px;
  transition: transform 0.2s, opacity 0.2s, top 0.2s, bottom 0.2s;
}

.mlt-burger__bars {
  top: 50%;
  transform: translateY(-50%);
}

.mlt-burger__bars::before,
.mlt-burger__bars::after {
  content: "";
  left: 0;
  right: 0;
}

.mlt-burger__bars::before { top: -9px; }
.mlt-burger__bars::after  { top: 9px; }

/* When the burger's aria-expanded is true (set by JS), morph to an X. */
.mlt-burger[aria-expanded="true"] .mlt-burger__bars {
  background: transparent;
}
.mlt-burger[aria-expanded="true"] .mlt-burger__bars::before {
  top: 0;
  transform: rotate(45deg);
}
.mlt-burger[aria-expanded="true"] .mlt-burger__bars::after {
  top: 0;
  transform: rotate(-45deg);
}

/* ----- Mobile (< 900px): show burger, hide nav until toggled ----- */
@media (max-width: 900px) {
  /* When mobile, the burger is the only visible content in the nav
   * region by default. Give the region a minimal background so it
   * doesn't disappear entirely (and the burger has something to sit
   * against). */
  .mlt-region--primary-nav {
    background: #fff;
    border-bottom: 1px solid var(--mlt-border);
    /* Reserve space for the burger so the region doesn't collapse. */
    min-height: 60px;
  }

  /* Show the burger, centred in the nav region. */
  .mlt-burger {
    display: flex;
    /* Sit the burger top-right of the nav region. */
    position: absolute;
    top: 8px;
    right: 16px;
    margin: 0;
    z-index: 5;
  }

  /* Hide the nav by default on mobile. Show only when JS adds
   * .mlt-nav--open. JS targets the <nav> element inside the menu block. */
  .mlt-region--primary-nav nav {
    display: none;
  }
  .mlt-region--primary-nav nav.mlt-nav--open {
    display: block;
  }

  .mlt-region--primary-nav nav > ul {
    flex-direction: column;
    align-items: stretch;
    padding: 0;
  }
  .mlt-region--primary-nav nav > ul > li {
    width: 100%;
  }
  .mlt-region--primary-nav nav > ul > li > a {
    padding: 12px 18px;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
  }
  /* On mobile we drop the absolute-positioned dropdown and just stack
   * the submenu inline. The :hover trigger doesn't work well on touch
   * anyway — for now sub-items are always visible when their parent is. */
  .mlt-region--primary-nav nav > ul > li > ul {
    position: static;
    display: block;
    width: 100%;
    box-shadow: none;
    border-radius: 0;
    background: rgba(0, 0, 0, 0.15);
    min-width: 0;
  }
  .mlt-region--primary-nav nav > ul > li > ul li a {
    padding-left: 36px;
  }

  /* Header — on mobile, stack logo and accreds vertically. */
  .mlt-header__inner {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }

  /* Accreditations: show on mobile, span full width, centre. */
  .mlt-header__accreds {
    width: 100%;
    text-align: center;
  }
  .mlt-header__accreds img {
    max-width: 100%;
    max-height: 50px;
    width: auto;
    margin: 0 auto;
  }
}

@media (max-width: 540px) {
  .mlt-header {
    padding: 14px 0;
  }
  .mlt-header__logo img {
    max-height: 56px;
  }
  .mlt-header__accreds img {
    max-height: 44px;
  }
}
