/* The page frame: container, sections, header, navigation, drawer, footer. */
@layer layout {

  /* ── Container and sections ──────────────────────────────────────────── */
  .container {
    width: min(100% - 2 * var(--gutter), var(--container));
    margin-inline: auto;
  }
  .container--narrow { width: min(100% - 2 * var(--gutter), var(--container-narrow)); }

  .section { padding-block: var(--section-y); }
  .section--alt { background: var(--color-bg-alt); }
  .section--tight { padding-block: calc(var(--section-y) * 0.6); }

  .stack > * + * { margin-top: var(--space-5); }

  .grid { display: grid; gap: var(--space-5); }
  .grid--2 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 22rem), 1fr)); }
  /* auto-fill, not auto-fit: a short list (one related article, two case
     studies) keeps card-sized columns instead of stretching across the row. */
  .grid--3 { grid-template-columns: repeat(auto-fill, minmax(min(100%, 18rem), 1fr)); }
  .grid--4 { grid-template-columns: repeat(auto-fill, minmax(min(100%, 14rem), 1fr)); }
  .grid--5 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 13rem), 1fr)); }

  main:focus { outline: none; }

  /* ── Header ──────────────────────────────────────────────────────────── */
  .site-header {
    position: sticky;
    top: 0;
    z-index: 50;
    height: var(--header-height);
    background: var(--white);
    border-bottom: 1px solid var(--line);
    transition: background-color var(--duration) var(--ease),
                border-color var(--duration) var(--ease),
                box-shadow var(--duration) var(--ease);
  }
  .site-header.is-scrolled { box-shadow: var(--shadow); border-color: transparent; }

  .site-header__inner {
    height: 100%;
    display: flex;
    align-items: center;
    gap: var(--space-5);
  }

  /* Over a navy hero the header starts transparent with light text, and turns
     solid white once the page moves. The hero pulls itself up underneath it. */
  .site-header--overlay {
    position: fixed;
    inset-inline: 0;
  }
  .site-header--overlay:not(.is-scrolled) {
    background: transparent;
    border-color: transparent;
    --color-heading: var(--white);
    --nav-link: var(--white);
    --nav-link-hover: var(--gold-300);
    --color-focus-ring: var(--white);
  }
  .site-header--overlay + .site-main > :first-child { padding-top: var(--header-height); }

  .brand {
    display: inline-flex;
    align-items: center;
    gap: var(--space-3);
    text-decoration: none;
    color: var(--color-heading);
    margin-right: auto;
  }
  .brand__mark { height: 2.5rem; flex: none; }
  .brand__word {
    font-family: var(--font-heading);
    font-weight: 800;
    font-size: 1.25rem;
    letter-spacing: 0.18em;
  }
  .brand:hover { color: var(--color-heading); }

  /* Desktop navigation. Hidden below 64rem, where the drawer takes over. */
  .site-nav { display: none; }
  .site-nav__list {
    display: flex;
    align-items: center;
    gap: var(--space-1);
    list-style: none;
    margin: 0;
    padding: 0;
  }

  .nav-link {
    --nav-link: var(--navy-900);
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    padding: var(--space-2) var(--space-3);
    border: 0;
    background: none;
    cursor: pointer;
    font-size: var(--text-sm);
    font-weight: 550;
    color: var(--nav-link);
    text-decoration: none;
    border-radius: var(--radius-sm);
  }
  .site-header--overlay:not(.is-scrolled) .nav-link { --nav-link: var(--white); }
  .nav-link:hover { color: var(--nav-link-hover, var(--gold-700)); }
  .nav-link[aria-current="page"] {
    text-decoration: underline;
    text-decoration-color: var(--color-accent-line);
    text-decoration-thickness: 2px;
    text-underline-offset: 8px;
  }
  .nav-link .icon { width: 1em; height: 1em; transition: transform var(--duration) var(--ease); }
  .nav-link[aria-expanded="true"] .icon { transform: rotate(180deg); }

  .header-cta { display: none; }

  /* The ☰ opener: shown by the drawer controller, hidden from 64rem up. */
  .nav-toggle {
    display: inline-grid;
    place-items: center;
    width: 2.75rem;
    height: 2.75rem;
    border: 1px solid var(--color-border-strong);
    border-radius: var(--radius);
    background: transparent;
    color: var(--color-heading);
    cursor: pointer;
  }
  .site-header--overlay:not(.is-scrolled) .nav-toggle { border-color: color-mix(in srgb, var(--white) 35%, transparent); }
  .nav-toggle .icon { width: 1.4rem; height: 1.4rem; }

  @media (min-width: 64rem) {
    .site-nav { display: block; }
    .header-cta { display: inline-flex; }
    .nav-toggle, .drawer { display: none !important; }
  }

  /* ── Services dropdown (desktop) ─────────────────────────────────────── */
  .dropdown { position: relative; }
  .dropdown__panel {
    position: absolute;
    top: calc(100% + var(--space-3));
    left: 50%;
    translate: -50% 0;
    width: min(34rem, 90vw);
    padding: var(--space-3);
    background: var(--white);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    --color-heading: var(--navy-900);
  }
  .dropdown__list { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--space-1); }
  .dropdown__item {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: var(--space-1) var(--space-3);
    align-items: start;
    padding: var(--space-3);
    border-radius: var(--radius);
    text-decoration: none;
    color: var(--ink-600);
    font-size: var(--text-sm);
    line-height: var(--leading-snug);
  }
  .dropdown__item:hover, .dropdown__item:focus-visible { background: var(--navy-50); color: var(--ink-600); }
  .dropdown__item .icon-badge { grid-row: span 2; }
  .dropdown__item strong { color: var(--navy-900); font-weight: 650; }
  .dropdown__all {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: var(--space-2);
    padding: var(--space-3);
    border-top: 1px solid var(--line);
    font-size: var(--text-sm);
    font-weight: 600;
    color: var(--navy-900);
    text-decoration: none;
  }
  .dropdown__all .icon { width: 1em; height: 1em; }

  /* ── Drawer (mobile navigation) ──────────────────────────────────────── */
  /* Ships as <dialog open> so that, with no JavaScript, it can render inline as
     a plain list of links (noscript.css un-hides it). With JavaScript it is
     hidden until opened as a modal, so it never flashes on page load. */
  .drawer:not(:modal) { display: none; }
  .drawer {
    border: 0;
    padding: 0;
    margin: 0;
    width: 100%;
    max-width: none;
    background: var(--white);
    color: var(--color-text);
    position: static;
  }
  .drawer:modal {
    position: fixed;
    inset: 0 0 0 auto;
    width: min(24rem, 100%);
    height: 100dvh;
    max-height: none;
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
  }
  /* The drawer lives inside the header, so over a navy hero it would inherit
     the overlay's white-on-navy colours and lose its wordmark and ✕ on the
     white panel. It resets them. (layout beats components, so these win over
     the overlay's logo-mark rules too.) */
  .drawer {
    --color-heading: var(--navy-900);
    --color-focus-ring: var(--navy-900);
  }
  .site-header .drawer .nav-toggle { border-color: var(--color-border-strong); color: var(--navy-900); }
  .site-header .drawer .logo-mark__img--default { display: block; }
  .site-header .drawer .logo-mark__img--light { display: none; }

  .drawer::backdrop { background: color-mix(in srgb, var(--navy-950) 55%, transparent); }
  @media (prefers-reduced-motion: no-preference) {
    .drawer:modal { animation: drawer-in 220ms var(--ease); }
    @keyframes drawer-in { from { translate: 100% 0; } }
  }

  .drawer__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: var(--header-height);
    padding-inline: var(--gutter);
    border-bottom: 1px solid var(--line);
  }
  .drawer__body { flex: 1; overflow-y: auto; padding: var(--space-4) var(--gutter); }
  .drawer__foot { padding: var(--space-4) var(--gutter) var(--space-6); border-top: 1px solid var(--line); }
  .drawer__foot .button { width: 100%; }

  .drawer__list { list-style: none; margin: 0; padding: 0; }
  .drawer__list > li { border-bottom: 1px solid var(--line); }
  .drawer__link, .drawer summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 3.25rem;
    padding-block: var(--space-2);
    font-family: var(--font-heading);
    font-weight: 650;
    font-size: var(--text-lg);
    color: var(--navy-900);
    text-decoration: none;
    cursor: pointer;
  }
  .drawer summary { list-style: none; }
  .drawer summary::-webkit-details-marker { display: none; }
  .drawer summary .icon { width: 1.1rem; height: 1.1rem; transition: transform var(--duration) var(--ease); }
  .drawer details[open] summary .icon { transform: rotate(180deg); }
  .drawer__sublist { list-style: none; margin: 0 0 var(--space-3); padding: 0 0 0 var(--space-3); border-left: 2px solid var(--gold-500); }
  .drawer__sublist a {
    display: block;
    padding: var(--space-2) 0;
    color: var(--ink-600);
    text-decoration: none;
    font-size: var(--text-base);
  }
  .drawer__sublist a:hover { color: var(--navy-900); }
  .drawer__link[aria-current="page"] { color: var(--gold-700); }

  /* ── Footer ──────────────────────────────────────────────────────────── */
  .site-footer {
    padding-block: var(--space-8) var(--space-6);
    font-size: var(--text-sm);
  }
  .site-footer__grid {
    display: grid;
    gap: var(--space-7) var(--space-6);
    grid-template-columns: 1fr;
  }
  @media (min-width: 40rem) {
    .site-footer__grid { grid-template-columns: 1fr 1fr; }
  }
  @media (min-width: 64rem) {
    .site-footer__grid { grid-template-columns: 1.4fr 1fr 1fr 1.2fr; }
  }
  .site-footer h2 {
    font-size: var(--text-xs);
    text-transform: uppercase;
    letter-spacing: var(--tracking-eyebrow);
    color: var(--color-eyebrow);
    margin-bottom: var(--space-4);
  }
  .site-footer ul { list-style: none; padding: 0; margin: 0; display: grid; gap: var(--space-3); }
  .site-footer a { color: var(--color-text-muted); text-decoration: none; }
  .site-footer a:hover { color: var(--white); text-decoration: underline; }
  .site-footer__about p { color: var(--color-text-muted); max-width: 26rem; }
  .site-footer__about .site-footer__tagline {
    margin-top: var(--space-5);
    font-family: var(--font-heading);
    font-weight: 650;
    color: var(--gold-300);
  }
  .site-footer__contact li { display: flex; gap: var(--space-3); align-items: flex-start; color: var(--color-text-muted); }
  .site-footer__contact .icon { width: 1.1rem; height: 1.1rem; flex: none; margin-top: 0.2em; color: var(--gold-300); }

  .site-footer .social-links { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-top: var(--space-5); }
  .site-footer .social-links a {
    display: inline-grid;
    place-items: center;
    width: 2.5rem;
    height: 2.5rem;
    border: 1px solid var(--dark-border);
    border-radius: var(--radius-pill);
    color: var(--white);
  }
  .site-footer .social-links a:hover { background: var(--gold-500); border-color: var(--gold-500); color: var(--navy-900); }
  .social-links .icon { width: 1.05rem; height: 1.05rem; }

  .site-footer__bottom {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-3) var(--space-5);
    justify-content: space-between;
    margin-top: var(--space-8);
    padding-top: var(--space-5);
    border-top: 1px solid var(--dark-border);
    color: var(--color-text-muted);
  }
  .site-footer__bottom p { margin: 0; }
  .site-footer .site-footer__bottom ul { display: flex; flex-wrap: wrap; gap: var(--space-5); }
}

/* ── Page structures (p5) ──────────────────────────────────────────────── */
@layer layout {
  .section--dark { background: var(--navy-900); }

  /* Heading on one side, content on the other; stacks on phones. */
  .split { display: grid; gap: var(--space-6) var(--space-8); align-items: start; }
  @media (min-width: 56rem) {
    .split { grid-template-columns: minmax(0, 5fr) minmax(0, 7fr); }
    .split--even { grid-template-columns: 1fr 1fr; }
    .split > .section-header { margin-bottom: 0; position: sticky; top: calc(var(--header-height) + var(--space-6)); }
  }

  .section-footer { margin-top: var(--space-7); display: flex; justify-content: center; }

  /* Cards in rows of up to three, with a short last row CENTRED rather than
     left hanging (five service divisions = three + two). */
  .grid--centered { display: flex; flex-wrap: wrap; justify-content: center; gap: var(--space-5); }
  .grid--centered > * { flex: 1 1 18rem; max-width: 100%; }
  @media (min-width: 56rem) {
    .grid--centered > * { flex: 0 1 calc((100% - 2 * var(--space-5)) / 3); }
  }
}
