/**
 * Site chrome: topbar, header nav, footer, Messenger FAB.
 *
 * Ported from the signed-off mock-up kit (`tokens.css` §6b–6d), which was
 * byte-identical across all 20 mock-ups. Literals replaced by the tokens that
 * already carried the same values.
 *
 * This chrome is not a section. It renders on every page from `header.php` and
 * `footer.php`, and a client cannot reorder or remove it – which is correct,
 * because the DMW licence line in the topbar and the licence paragraph in the
 * footer are compliance surfaces, not content.
 */

/* ---------------------------------------------------------------------------
 * 1. TOPBAR
 * ------------------------------------------------------------------------- */
.topbar {
  background: var(--navy);
  color: var(--on-dark-muted);
  padding-block: 0.5rem;
  padding-inline: var(--gutter);
  font-size: var(--text-xs);
  font-weight: 600;
}
.topbar__inner {
  max-width: var(--container-width);
  margin-inline: auto;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-1) var(--s-3);
}
.topbar__meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--s-1) var(--s-4);
}
.topbar__meta svg { width: 14px; height: 14px; }
.topbar__meta span {
  display: inline-flex;
  align-items: center;
  gap: 0.45em;
}
.topbar__meta a { color: inherit; }
.topbar__meta a:hover { color: var(--white); }

/* Below 720px the licence number and the four language controls cannot share
   a row: neither is compressible – the licence line is a single compliance
   string and the controls are pills – so `space-between` squeezed the licence
   into a 95px column and broke it over five lines, and stacked 日本語 one
   character per line. They get a row each instead, centred, which is the
   honest degradation of a two-item bar. */
@media (max-width: 720px) {
  .topbar__meta span.hide-s { display: none; }

  .topbar__inner,
  .topbar__meta { justify-content: center; }
  .topbar__meta { text-align: center; }
  .topbar__inner > * { flex: 1 1 100%; }
}

.lang-switch {
  display: inline-flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 2px;
}
.lang-switch button,
.lang-switch a {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--on-dark-muted);
  /* A label is a language name, never a phrase. Without this 日本語 and 中文
     break one character per line as soon as the bar is tight. */
  white-space: nowrap;
  padding: 0.3em 0.8em;
  border-radius: var(--r-pill);
  transition:
    background-color var(--dur-fast) ease,
    color var(--dur-fast) ease;
}
.lang-switch button:hover,
.lang-switch a:hover {
  color: var(--white);
  background: var(--on-dark-hairline-soft);
}
.lang-switch button[aria-pressed="true"],
.lang-switch a[aria-current="true"] {
  background: var(--gold);
  color: var(--navy);
}

/* ---------------------------------------------------------------------------
 * 2. HEADER + PRIMARY NAV
 * ------------------------------------------------------------------------- */
/* The frosted surface lives on a pseudo-element, and that placement is
   load-bearing rather than cosmetic.
 *
 * `backdrop-filter` on an element makes it the containing block for every
 * `position: fixed` descendant. While the blur sat on `.site-header` itself,
 * the mobile drawer – which is `position: fixed` and expects the viewport –
 * resolved `inset-block: 0` against the header's padding box instead. It came
 * out roughly 120px tall on a 667px screen, which is exactly the "limited
 * height container that forces scrolling to reach items" in F-11.
 *
 * Moving the blur to `::before` keeps the design identical and hands the
 * drawer the viewport back. Do not move `backdrop-filter`, `filter`,
 * `transform`, `perspective` or `will-change` back onto `.site-header`. */
.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: transparent;
  border-bottom: 1px solid transparent;
  padding-inline: var(--gutter);
  transition:
    border-color var(--dur-normal) ease,
    box-shadow var(--dur-normal) ease;
}
.site-header::before {
  content: "";
  position: absolute;
  inset-block: 0;
  inset-inline: 0;
  z-index: -1;
  background: var(--header-surface);
  backdrop-filter: var(--header-blur);
  -webkit-backdrop-filter: var(--header-blur);
}
.site-header[data-scrolled="true"] {
  border-bottom-color: var(--line);
  box-shadow: var(--shadow-header);
}

.nav {
  max-width: var(--container-width);
  margin-inline: auto;
  padding-block: 0.8rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-4);
}
.nav__brand {
  display: inline-flex;
  align-items: center;
  line-height: 0;
}
.nav__brand img { height: 48px; width: auto; display: block; }
@media (max-width: 480px) {
  .nav__brand img { height: 40px; }
}

.nav__links {
  display: flex;
  align-items: center;
  gap: var(--s-4);
}
.nav__link {
  font-weight: 600;
  font-size: var(--text-s);
  color: var(--ink-soft);
  padding-block: 0.4rem;
  position: relative;
  transition: color var(--dur-fast) ease;
  white-space: nowrap;
}
.nav__link::after {
  content: "";
  position: absolute;
  inset-inline: 0;
  bottom: -2px;
  height: 2px;
  background: var(--red);
  border-radius: 2px;
  transform: scaleX(0);
  transform-origin: left;
  transition: transform var(--dur-normal) var(--ease-out-expo);
}
.nav__link:hover,
.nav__link[aria-current="page"] { color: var(--blue); }
.nav__link:hover::after,
.nav__link[aria-current="page"]::after { transform: scaleX(1); }

.nav__actions {
  display: flex;
  align-items: center;
  gap: var(--s-3);
}
.nav__cta {
  padding-block: 0.65rem;
  padding-inline: 1.35rem;
  min-height: 44px;
  font-size: var(--text-s);
}

/* --- Dropdown groups: About / Services / Applicants ------------------------
   Opens on hover, on focus-within, and on click (main.js). Escape closes.
   The CSS paths are what make it work with JavaScript off. */
.nav__item { position: relative; }
.nav__link--sub {
  display: inline-flex;
  align-items: center;
  gap: 0.4em;
  background: none;
  border: none;
}
.nav__caret {
  width: 11px;
  height: 11px;
  flex: none;
  transition: transform var(--dur-fast) var(--ease-out-soft);
}
.nav__item[data-open="true"] .nav__caret { transform: rotate(180deg); }

.nav__sub {
  position: absolute;
  top: calc(100% + 14px);
  inset-inline-start: calc(var(--s-3) * -1);
  min-width: 238px;
  padding: 0.5rem;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--r-m);
  box-shadow: var(--shadow-m);
  display: flex;
  flex-direction: column;
  gap: 2px;
  opacity: 0;
  visibility: hidden;
  transform: translateY(8px);
  transition:
    opacity var(--dur-fast) ease,
    transform var(--dur-normal) var(--ease-out-expo),
    visibility var(--dur-fast);
}
/* Invisible bridge, so the pointer can travel from the link to the panel
   without crossing a gap that closes it. */
.nav__sub::before {
  content: "";
  position: absolute;
  inset-inline: 0;
  top: -14px;
  height: 14px;
}
.nav__sub a {
  padding: 0.6rem 0.9rem;
  border-radius: var(--r-s);
  font-size: var(--text-s);
  font-weight: 600;
  color: var(--ink-soft);
  white-space: nowrap;
  transition:
    background-color var(--dur-fast) ease,
    color var(--dur-fast) ease;
}
.nav__sub a:hover { background: var(--blue-tint-05); color: var(--blue); }
.nav__sub a[aria-current="page"] { background: var(--blue-tint-10); color: var(--blue); }

/* Two open paths, and which one applies depends on whether JS is running.
 *
 * With JavaScript OFF, `:focus-within` is the only thing a keyboard user has,
 * so it opens the panel. That is the contract in the `parts/nav.php` header
 * and it is not negotiable.
 *
 * With JavaScript ON, `data-open` is the single source of truth. This is the
 * fix for F-11: `:focus-within` used to hold the panel open no matter what the
 * script did, so Escape set `data-open="false"` and `aria-expanded="false"`
 * and the panel stayed on screen because focus was still inside it – measured,
 * not assumed. It also meant `aria-expanded="false"` was announced over a
 * visibly open panel whenever focus merely landed on the trigger. `main.js`
 * moves focus to the trigger when it closes a panel, so nothing is left
 * focused inside a hidden box.
 *
 * `:hover` stays unconditional. It is pointer-only, it cannot strand focus,
 * and it is the signed-off desktop behaviour. */
.nav__item:hover > .nav__sub,
html:not(.js) .nav__item:focus-within > .nav__sub,
.nav__item[data-open="true"] > .nav__sub {
  opacity: 1;
  visibility: visible;
  transform: none;
}
.nav__item:hover > .nav__link--sub,
.nav__item[data-open="true"] > .nav__link--sub { color: var(--blue); }
.nav__item[data-active="true"] > .nav__link--sub { color: var(--blue); }
.nav__item[data-active="true"] > .nav__link--sub::after { transform: scaleX(1); }

/* --- Mobile drawer -------------------------------------------------------- */
.nav__toggle {
  display: none;
  width: 46px;
  height: 46px;
  border-radius: var(--r-s);
  position: relative;
}
.nav__toggle span,
.nav__toggle span::before,
.nav__toggle span::after {
  content: "";
  position: absolute;
  inset-inline: 0;
  width: 22px;
  height: 2px;
  margin-inline: auto;
  background: var(--ink);
  border-radius: 2px;
  transition:
    transform var(--dur-fast) ease,
    opacity var(--dur-fast) ease;
}
.nav__toggle span { top: 50%; margin-top: -1px; }
.nav__toggle span::before { top: -7px; }
.nav__toggle span::after { top: 7px; }
.nav__toggle[aria-expanded="true"] span { background: transparent; }
.nav__toggle[aria-expanded="true"] span::before { transform: translateY(7px) rotate(45deg); }
.nav__toggle[aria-expanded="true"] span::after { transform: translateY(-7px) rotate(-45deg); }

@media (max-width: 1060px) {
  /* In the drawer the dropdown panels become accordions, not overlays. */
  .nav__item { inline-size: 100%; }
  .nav__link--sub {
    inline-size: 100%;
    justify-content: space-between;
    font-size: var(--text-lg);
  }
  .nav__sub {
    position: static;
    opacity: 1;
    visibility: visible;
    transform: none;
    border: none;
    box-shadow: none;
    background: none;
    padding-block: 0;
    padding-inline: var(--s-3) 0;
    margin-block: 0.25rem 0.5rem;
    display: none;
  }
  .nav__sub::before { display: none; }

  /* Inside the drawer an accordion is driven by `data-open` and by nothing
     else. The block this replaces carried
       `.nav__item:hover > .nav__sub,
        .nav__item:focus-within > .nav__sub { display: none; }`
     followed by a rescue rule for `:hover` only. Those matched at the same
     specificity as `[data-open="true"]` and came later in the source, so
     focusing the trigger – which is exactly what pressing Enter on it does –
     put the panel back to `display: none` in the same frame it opened. A
     keyboard user could not open a drawer sub-menu at all; a pointer user saw
     it only while still hovering. The base `.nav__sub` above is already
     `display: none`, so the two suppression rules were never doing any work
     the cascade was not already doing. */
  .nav__item[data-open="true"] > .nav__sub { display: flex; }

  .nav__sub a { font-size: var(--text-base); padding-inline: 0; }

  /* The closed drawer is `display: none`, not a box parked off-canvas.
   *
   * A `position: fixed` box translated past the inline-end edge still counts
   * toward the document's scrollable overflow. That single declaration made
   * `documentElement.scrollWidth` 609px at a 320px viewport, 713px at 375px
   * and 1398px at 1024px – a phantom page ~340px wider than the screen at
   * every width this media query covers, which is precisely the set of widths
   * F-12 to F-15 were raised at. 1440px and 1920px were clean because the
   * drawer is not laid out there at all.
   *
   * `display: none` removes the box, so there is nothing to overflow. The
   * slide-in survives via @starting-style; a browser without it opens the
   * drawer without the animation, which is a fair degradation. Do not go back
   * to hiding this with a transform, an off-canvas offset, or `visibility` –
   * all three were measured and all three keep the phantom width. */
  .nav__links {
    --nav-drawer-offset: 110%;

    position: fixed;
    inset-block: 0;
    inset-inline-start: auto;
    inset-inline-end: 0;
    inline-size: min(82vw, 340px);
    display: none;
    flex-direction: column;
    align-items: flex-start;
    justify-content: flex-start;
    gap: var(--s-2);
    background: var(--paper);
    padding-block: var(--s-8) var(--s-5);
    padding-inline: var(--s-5);
    box-shadow: var(--shadow-m);
    overflow-y: auto;
    overscroll-behavior: contain;
  }
  /* `inset-block: 0` rather than a `100vh` height, deliberately: a fixed box
     is bounded by the viewport as the mobile toolbar collapses, so it never
     develops the dead strip that `100vh` leaves under a retracting toolbar
     and never needs `100dvh` to compensate. */
  [dir="rtl"] .nav__links { --nav-drawer-offset: -110%; }

  .nav__links[data-open="true"] {
    display: flex;
    translate: 0;
    transition: translate var(--dur-normal) var(--ease-out-expo);
  }
  @starting-style {
    .nav__links[data-open="true"] { translate: var(--nav-drawer-offset); }
  }

  .nav__link { font-size: var(--text-lg); }
  .nav__toggle { display: flex; position: relative; z-index: 110; }
  .nav__cta { display: none; }
}

/* ---------------------------------------------------------------------------
 * 3. FOOTER
 * ------------------------------------------------------------------------- */
.site-footer {
  background: var(--navy);
  color: var(--footer-ink);
  padding-block: var(--section-space-m) var(--s-6);
  padding-inline: var(--gutter);
}
.footer__grid {
  max-width: var(--container-width);
  margin-inline: auto;
  display: grid;
  grid-template-columns: 1.5fr 1fr 1fr 1.2fr;
  gap: var(--s-6) var(--s-5);
}
.footer__logo {
  height: 56px;
  width: auto;
  display: block;
  margin-bottom: var(--s-3);
}
.footer__tagline {
  color: var(--footer-tagline);
  max-width: 36ch;
  font-size: var(--text-s);
  line-height: 1.6;
}
.footer__tagline b { color: var(--gold); font-weight: 700; }

.footer__col h3 {
  color: var(--white);
  font-size: var(--text-xs);
  font-family: var(--body);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  margin-bottom: var(--s-3);
}
.footer__col ul {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}
.footer__col a {
  color: var(--footer-ink);
  font-size: var(--text-s);
  transition: color var(--dur-fast) ease;
}
.footer__col a:hover { color: var(--white); }

.footer__social {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-2);
  margin-top: var(--s-4);
}
.footer__social a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: var(--r-pill);
  background: var(--on-dark-surface);
  border: 1px solid var(--on-dark-hairline);
  color: var(--footer-ink);
  font-size: var(--text-xs);
  font-weight: 700;
  transition:
    background-color var(--dur-fast) ease,
    color var(--dur-fast) ease;
}
.footer__social a:hover {
  background: var(--on-dark-surface-hover);
  color: var(--white);
}
.footer__social svg { width: 18px; height: 18px; }

.footer__contact li {
  display: flex;
  gap: 0.6em;
  align-items: flex-start;
  font-size: var(--text-s);
  color: var(--footer-ink);
}
.footer__contact svg {
  width: 16px;
  height: 16px;
  flex: none;
  margin-top: 0.2em;
  color: var(--gold);
}

.footer__chat {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  margin-top: var(--s-3);
  min-height: 44px;
  background: var(--on-dark-surface);
  border: 1px solid var(--on-dark-hairline);
  color: var(--white);
  padding: 0.7rem 1.1rem;
  border-radius: var(--r-pill);
  font-weight: 700;
  font-size: var(--text-s);
  transition:
    background-color var(--dur-fast) ease,
    transform var(--dur-fast) var(--ease-out-soft);
}
.footer__chat:hover {
  background: var(--on-dark-surface-hover);
  transform: translateY(-2px);
}
.footer__chat svg { width: 18px; height: 18px; }

.footer__bottom {
  max-width: var(--container-width);
  margin: var(--s-7) auto 0;
  padding-top: var(--s-4);
  border-top: 1px solid var(--on-dark-hairline-soft);
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-3) var(--s-5);
  align-items: center;
  justify-content: space-between;
  font-size: var(--text-xs);
  color: var(--footer-ink-muted);
}
.footer__legal {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-3) var(--s-4);
}
.footer__legal a:hover { color: var(--white); }

.footer__licence {
  max-width: var(--container-width);
  margin: var(--s-4) auto 0;
  font-size: var(--text-xs);
  color: var(--footer-ink-muted);
  line-height: 1.6;
}

@media (max-width: 900px) {
  .footer__grid { grid-template-columns: 1fr 1fr; }
  .footer__col--brand { grid-column: 1 / -1; }
}
@media (max-width: 520px) {
  .footer__grid { grid-template-columns: 1fr; }
}

/* ---------------------------------------------------------------------------
 * 4. MESSENGER CHAT FAB
 * ------------------------------------------------------------------------- */
.chat-fab {
  position: fixed;
  inset-inline-end: clamp(1rem, 2vw, 2rem);
  bottom: clamp(1rem, 2vw, 2rem);
  z-index: 90;
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  min-height: 48px;
  background: var(--blue);
  color: var(--white);
  font-weight: 700;
  font-size: var(--text-s);
  padding: 0.85rem 1.3rem;
  border-radius: var(--r-pill);
  box-shadow: var(--shadow-blue);
  transition:
    transform var(--dur-fast) var(--ease-out-soft),
    background-color var(--dur-fast) ease;
}
.chat-fab:hover { transform: translateY(-3px); background: var(--blue-deep); }
.chat-fab svg { width: 20px; height: 20px; }

@media (max-width: 600px) {
  .chat-fab .chat-fab__label { display: none; }
  .chat-fab { padding: 0.85rem; }
}
