/**
 * @file
 * MLT Modern — Header (logo strip + accreditations + nav).
 *
 * The header in our slim region setup is the `header` region in
 * page.html.twig. Two blocks live there, rendered in weight order:
 *
 *   1. MLT Modern — Header Logo Strip   (custom HTML block; markup below)
 *   2. Main navigation                  (Drupal core system_menu_block:main)
 *
 * Both are wrapped by the region's <header class="mlt-region--header">,
 * and this stylesheet styles BOTH the custom strip and the core menu
 * block's plain HTML so they read as one cohesive header.
 *
 * Custom HTML block markup pattern (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>
 *
 * Menu CSS targets the <nav> element produced by core's menu block.
 * For dropdowns to render, the menu block's "Number of levels to display"
 * setting must be > 1 (set in the block's configure form).
 */

/* -----------------------------------------------------------------------
 * Logo strip (custom block content)
 * ----------------------------------------------------------------------- */
.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;
}

/* -----------------------------------------------------------------------
 * Main navigation — restyling the existing Superfish menu block.
 *
 * 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 our header region. The active-page link gets .is-active
 * from Drupal core automatically.
 *
 * Markup (Drupal core menu block, depth = unlimited):
 *   <header class="mlt-region mlt-region--header">
 *     ... logo block ...
 *     <div>
 *       <nav role="navigation" id="block-...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>
 *   </header>
 *
 * For dropdowns to appear in the HTML, the menu block must be configured
 * with "Number of levels to display" > 1 in its block settings.
 * ----------------------------------------------------------------------- */

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

/* Constrain the menu's inner content to container width. */
.mlt-region--header 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--header nav > ul > li {
  position: relative;
  list-style: none;
  margin: 0;
  padding: 0;
}

/* Top-level links. */
.mlt-region--header 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--header nav > ul > li > a:hover,
.mlt-region--header nav > ul > li > a:focus,
.mlt-region--header 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--header 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--header 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--header nav > ul > li:hover > ul,
.mlt-region--header nav > ul > li:focus-within > ul {
  display: block;
}

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

.mlt-region--header 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--header nav ul ul li a:hover,
.mlt-region--header nav ul ul li a:focus,
.mlt-region--header 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+). If you
 * need to support older browsers, add a "menuparent" class via preprocess
 * in mlt_modern.theme and target that instead. */
.mlt-region--header nav > ul > li:has(> ul) > a::after {
  content: " ▾";
  font-size: 10px;
  opacity: 0.7;
  margin-left: 4px;
}

/* -----------------------------------------------------------------------
 * Burger menu button — visible only on mobile (< 900px). Placed in the
 * header region as its own custom HTML block. Markup:
 *
 *   <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>
 *
 * 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. */
  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): collapse nav by default, show burger ----- */
@media (max-width: 900px) {
  .mlt-burger {
    display: flex;
  }

  /* Hide the nav by default on mobile. Show only when JS adds .mlt-nav--open. */
  .mlt-region--header nav {
    display: none;
  }
  .mlt-region--header nav.mlt-nav--open {
    display: block;
  }

  .mlt-region--header nav > ul {
    flex-direction: column;
    align-items: stretch;
    padding: 0;
  }
  .mlt-region--header nav > ul > li {
    width: 100%;
  }
  .mlt-region--header 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--header 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--header nav > ul > li > ul li a {
    padding-left: 36px;
  }

  /* Hide accreditations on mobile to free up room for the burger. */
  .mlt-header__accreds {
    display: none;
  }
}

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