/* Responsive navigation menu (file added by the APE, not part of Carlos's
   export). Injected at build time after Carlos's stylesheets; logic in
   ape-nav.js, which sets the ape-nav-* classes. See docs/menu.md. */

/* --- Without JS (or before initialisation): full list that wraps, 44 px
   targets, no more clipped scrolling row. --- */
html:not(.ape-nav-js) .site-header .site-global-nav,
html:not(.ape-nav-js) .cc-header-inner nav.portal-global-nav {
  flex-wrap: wrap;
  overflow: visible;
  row-gap: 0;
}
html:not(.ape-nav-js) .site-header .site-global-nav > a,
html:not(.ape-nav-js) .cc-header-inner nav.portal-global-nav > a {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding-block: 0;
}
@media (max-width: 760px) {
  html:not(.ape-nav-js) .site-header .site-global-nav,
  html:not(.ape-nav-js) .cc-header-inner nav.portal-global-nav {
    column-gap: 16px;
    padding: 0 0 6px;
  }
  html:not(.ape-nav-js) .site-header .site-global-nav > a,
  html:not(.ape-nav-js) .cc-header-inner nav.portal-global-nav > a {
    font-size: .9375rem;
  }
}

/* --- Same header geometry on every page (no shift between pages) ---
   Classic scrollbars (Windows, macOS with a mouse): short pages, and portal
   pages before portal.js renders #app, had no scrollbar, so the centred
   header sat 7.5 px further right than on long pages and jumped back once
   the scrollbar appeared. Reserve the gutter on every page. */
html { scrollbar-gutter: stable; }
@supports not (scrollbar-gutter: stable) { html { overflow-y: scroll; } }
/* styles.css (home) sets the links at .84rem, portal.css at .82rem: the
   right-aligned links moved by up to 14 px between the two templates. One
   size for both, above Carlos's 760 px breakpoint (menu mode and the small
   screen no-JS list set their own size). */
@media (min-width: 760.02px) {
  html:not(.ape-nav-menu) :is(.site-header .site-global-nav, .cc-header-inner nav.portal-global-nav) > a { font-size: .84rem; }
}

/* --- Before ape-nav.js runs (first visit, cold cache) ---
   The deferred script can arrive after the first paint: the no-JS list was
   painted, then replaced by the bar or the menu (layout shift of the header
   and of the page below). When scripting is enabled, the header already gets
   the final grid and height, with the links and the language switcher
   hidden (their labels still change: short labels, FR | EN | 中文), until
   ape-nav.js sets html.ape-nav-js. The mode is guessed by width, from the
   French bar threshold (French is the build language). ape-nav.js sets
   html.ape-nav-off if it cannot initialise, which restores the no-JS list;
   if it never loads, the hidden parts reappear after 3 s. Without
   scripting, or in a browser without the scripting media feature, the no-JS
   list above applies. */
@media (scripting: enabled) {
  html:not(.ape-nav-js):not(.ape-nav-off) :is(.site-header .header-inner, .cc-header-inner) {
    display: grid;
    align-items: center;
    flex-wrap: nowrap;
  }
  html:not(.ape-nav-js):not(.ape-nav-off) :is(.site-header .header-inner, .cc-header-inner) > :is(a.brand, a.cc-brand) {
    grid-area: brand;
    justify-self: start;
  }
  html:not(.ape-nav-js):not(.ape-nav-off) :is(.site-header .header-inner, .cc-header-inner) > .language-switch {
    grid-area: lang;
    justify-self: end;
    gap: 2px;
    padding: 2px;
    visibility: hidden;
    animation: ape-nav-reveal 0s 3s forwards;
  }
  html:not(.ape-nav-js):not(.ape-nav-off) :is(.site-header .header-inner, .cc-header-inner) > .language-switch .language-option {
    min-width: 44px;
    min-height: 44px;
    padding: 0 8px;
    font-size: .875rem;
    font-weight: 600;
  }
  html:not(.ape-nav-js):not(.ape-nav-off) :is(.site-header .header-inner, .cc-header-inner) > nav {
    grid-area: nav;
    visibility: hidden;
    animation: ape-nav-reveal 0s 3s forwards;
  }
}
@media (scripting: enabled) and (min-width: 1060px) {
  html:not(.ape-nav-js):not(.ape-nav-off) :is(.site-header .header-inner, .cc-header-inner) {
    grid-template-columns: auto minmax(0, 1fr) auto;
    grid-template-areas: "brand nav lang";
    column-gap: 24px;
    row-gap: 0;
    min-height: 88px;
    padding-block: 0;
  }
  html:not(.ape-nav-js):not(.ape-nav-off) :is(.site-header .header-inner, .cc-header-inner) > nav {
    display: flex;
    flex: none;
    flex-wrap: nowrap;
    justify-content: flex-end;
    width: auto;
    min-width: 0;
    margin: 0;
    padding: 0;
    overflow: hidden;
  }
}
@media (scripting: enabled) and (max-width: 1059.98px) {
  html:not(.ape-nav-js):not(.ape-nav-off) :is(.site-header .header-inner, .cc-header-inner) {
    grid-template-columns: auto minmax(0, 1fr) auto auto;
    grid-template-areas: "brand . lang toggle" "nav nav nav nav";
    column-gap: 8px;
    row-gap: 0;
    min-height: 0;
    padding-block: 12px;
  }
  /* Collapsed, as in menu mode; the "Menu" button does not exist yet.
     Not display: none, which would stop the 3 s reveal animation. */
  html:not(.ape-nav-js):not(.ape-nav-off) :is(.site-header .header-inner, .cc-header-inner) > nav {
    flex-wrap: wrap;
    max-height: 0;
    margin: 0;
    padding: 0;
    overflow: hidden;
    animation-name: ape-nav-reveal-list;
  }
}
@keyframes ape-nav-reveal { to { visibility: visible; } }
@keyframes ape-nav-reveal-list { to { visibility: visible; max-height: none; overflow: visible; } }

/* --- Shared by both modes --- */
/* An entry hidden with the hidden attribute (home page: it follows its card,
   see home-portal.js) stays hidden in every mode, whatever the display rule. */
:is(.site-header .site-global-nav, .cc-header-inner nav.portal-global-nav) > a[hidden] { display: none !important; }
html.ape-nav-js .ape-nav-inner {
  display: grid;
  align-items: center;
  flex-wrap: nowrap;
}
html.ape-nav-js .ape-nav-inner > .ape-nav-brand { grid-area: brand; justify-self: start; }
html.ape-nav-js .ape-nav-inner > .language-switch {
  grid-area: lang;
  justify-self: end;
  gap: 2px;
  padding: 2px;
}
html.ape-nav-js .ape-nav-inner > .language-switch .language-option {
  min-width: 44px;
  min-height: 44px;
  padding: 0 8px;
  font-size: .875rem;
  font-weight: 600;
}
html.ape-nav-js .ape-nav-inner > .ape-nav > a:focus-visible,
html.ape-nav-js .ape-nav-toggle:focus-visible {
  outline: 3px solid #327ba8;
  outline-offset: 2px;
  border-radius: 4px;
}

/* "Menu" button (visible in menu mode only). */
html.ape-nav-js .ape-nav-toggle {
  grid-area: toggle;
  display: none;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-width: 44px;
  min-height: 44px;
  margin: 0;
  padding: 0 14px;
  border: 1px solid #b9c9d4;
  border-radius: 8px;
  background: #fff;
  color: #243642;
  font: 600 1rem/1 Arial, Helvetica, sans-serif;
  cursor: pointer;
  white-space: nowrap;
}
html.ape-nav-js .ape-nav-toggle:hover { background: #eef3f6; }
html.ape-nav-js .ape-nav-toggle[aria-expanded="true"] { background: #243642; border-color: #243642; color: #fff; }
.ape-nav-toggle-bars {
  position: relative;
  display: block;
  width: 18px;
  height: 2px;
  border-radius: 1px;
  background: currentColor;
  box-shadow: 0 -6px 0 currentColor, 0 6px 0 currentColor;
}

/* --- Bar mode: everything on one line --- */
html.ape-nav-bar .ape-nav-inner {
  grid-template-columns: auto minmax(0, 1fr) auto;
  grid-template-areas: "brand nav lang";
  column-gap: 24px;
  row-gap: 0;
  min-height: 88px;
  padding-block: 0;
}
html.ape-nav-bar .ape-nav-inner > .ape-nav {
  grid-area: nav;
  justify-self: stretch;
  display: flex;
  flex: none;
  flex-wrap: nowrap;
  justify-content: flex-end;
  align-items: center;
  gap: 0 12px;
  width: auto;
  min-width: 0;
  margin: 0;
  padding: 0;
  overflow: visible;
}
html.ape-nav-bar .ape-nav-inner > .ape-nav > a {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding-block: 0;
  white-space: nowrap;
}
/* Administration: 44 × 44 padlock; the text stays for screen readers
   (plus aria-label and title set by ape-nav.js). */
html.ape-nav-bar .ape-nav-inner > .ape-nav > a.ape-nav-admin {
  position: relative;
  justify-content: center;
  width: 44px;
  min-width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 8px;
  overflow: hidden;
  font-size: 0;
  color: #243642;
  text-decoration: none;
}
html.ape-nav-bar .ape-nav-inner > .ape-nav > a.ape-nav-admin::before {
  content: "";
  width: 22px;
  height: 22px;
  background: currentColor;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='4.5' y='10.5' width='15' height='10' rx='2'/%3E%3Cpath d='M8 10.5V7a4 4 0 0 1 8 0v3.5'/%3E%3Ccircle cx='12' cy='15.5' r='1.2' fill='black'/%3E%3C/svg%3E") center / contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='4.5' y='10.5' width='15' height='10' rx='2'/%3E%3Cpath d='M8 10.5V7a4 4 0 0 1 8 0v3.5'/%3E%3Ccircle cx='12' cy='15.5' r='1.2' fill='black'/%3E%3C/svg%3E") center / contain no-repeat;
}
html.ape-nav-bar .ape-nav-inner > .ape-nav > a.ape-nav-admin:hover,
html.ape-nav-bar .ape-nav-inner > .ape-nav > a.ape-nav-admin[aria-current="page"] { background: #e9f1f7; }
/* Link underline, bar mode and no-JS list, same on both headers: a single
   2px line at the bottom of the link box, never a text underline.
   styles.css (home) only sets a coral border on hover, while portal.css adds
   text-decoration: underline on :hover and :focus-visible on top of
   style.css's coral border, hence a double underline on portal pages.
   - hover: half-transparent coral line;
   - current page: solid coral line (also when hovered);
   - keyboard focus: the 3px #327ba8 outline, no extra line.
   The padlock (Administration) keeps its own style; menu mode has its own
   rules below. :not(.ape-nav-menu) keeps these out of the panel. */
html:not(.ape-nav-menu) :is(.site-header .site-global-nav, .cc-header-inner nav.portal-global-nav) > a:not(.ape-nav-admin) {
  text-decoration: none;
  border-bottom: 2px solid transparent;
}
html:not(.ape-nav-menu) :is(.site-header .site-global-nav, .cc-header-inner nav.portal-global-nav) > a:not(.ape-nav-admin):hover {
  border-bottom-color: rgb(240 130 112 / .5);
}
html:not(.ape-nav-menu) :is(.site-header .site-global-nav, .cc-header-inner nav.portal-global-nav) > a[aria-current="page"]:not(.ape-nav-admin) {
  border-bottom-color: #f08270;
}

/* --- Menu mode: button and panel expanded in the flow --- */
html.ape-nav-menu .ape-nav-inner {
  grid-template-columns: auto minmax(0, 1fr) auto auto;
  grid-template-areas: "brand . lang toggle" "nav nav nav nav";
  column-gap: 8px;
  row-gap: 0;
  min-height: 0;
  padding-block: 12px;
}
html.ape-nav-menu .ape-nav-toggle { display: inline-flex; }
html.ape-nav-menu .ape-nav-inner > .ape-nav {
  grid-area: nav;
  justify-self: stretch;
  display: none;
  width: auto;
  margin: 0;
  padding: 0;
  overflow: visible;
}
html.ape-nav-menu .ape-nav-open .ape-nav-inner > .ape-nav {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  column-gap: 24px;
  margin-top: 12px;
  padding-top: 4px;
  border-top: 1px solid #e3eaf0;
  animation: ape-nav-in .16s ease-out;
}
html.ape-nav-menu .ape-nav-inner > .ape-nav > a {
  display: flex;
  align-items: center;
  min-height: 48px;
  padding: 10px 8px;
  border: 0;
  border-bottom: 1px solid #eef2f5;
  color: #243642;
  font-size: 16px;
  font-weight: 600;
  line-height: 1.3;
  white-space: normal;
  text-decoration: none;
}
html.ape-nav-menu .ape-nav-inner > .ape-nav > a:hover { background: #f2f6f9; }
html.ape-nav-menu .ape-nav-inner > .ape-nav > a[aria-current="page"] {
  padding-left: 14px;
  background: #f2f6f9;
  box-shadow: inset 4px 0 0 #f08270;
  font-weight: 700;
}
/* Administration set apart, at the bottom, below a separator (#4b5c68 on white: 6.9:1). */
html.ape-nav-menu .ape-nav-inner > .ape-nav > a.ape-nav-admin {
  grid-column: 1 / -1;
  margin-top: 10px;
  border-top: 2px solid #c9d6df;
  border-bottom: 0;
  color: #4b5c68;
  font-weight: 500;
}
@media (min-width: 600px) {
  html.ape-nav-menu .ape-nav-open .ape-nav-inner > .ape-nav { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
/* Very small screens: icon only, the label stays for screen readers. */
@media (max-width: 359.98px) {
  html.ape-nav-menu .ape-nav-toggle { padding: 0; width: 44px; }
  html.ape-nav-menu .ape-nav-toggle-label {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }
  html.ape-nav-menu .ape-nav-inner { column-gap: 6px; }
}
@keyframes ape-nav-in {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: none; }
}
@media (prefers-reduced-motion: reduce) {
  html.ape-nav-menu .ape-nav-open .ape-nav-inner > .ape-nav { animation: none; }
}
@media print {
  .ape-nav-toggle { display: none !important; }
}

/* Notifications (portal.js #notice): small box at the top right on desktop,
   instead of a centred banner covering the form. Bottom of the screen on phones.
   Overrides style.css (Carlos) without touching his file. */
.cc-app #notice:not(:empty) {
  top: 96px; right: 24px; bottom: auto; left: auto; transform: none;
  width: auto; max-width: min(360px, calc(100vw - 32px));
  background: #fff; color: var(--cc-ink, #243642);
  border: 1px solid var(--cc-line, #dce5eb); border-left: 4px solid #327ba8;
  border-radius: 10px; padding: 12px 16px; font-size: .9375rem; line-height: 1.45;
  box-shadow: 0 8px 28px #24364224; z-index: 30;
  animation: ape-notice-in .18s ease-out;
}
@keyframes ape-notice-in { from { opacity: 0; transform: translateX(12px); } to { opacity: 1; transform: none; } }
@media (max-width: 600px) {
  .cc-app #notice:not(:empty) { top: auto; right: 16px; left: 16px; bottom: 16px; max-width: none; }
  @keyframes ape-notice-in { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
}
@media (prefers-reduced-motion: reduce) {
  .cc-app #notice:not(:empty) { animation: none; }
}

/* Admin section picker (portal.css makes it span the whole viewport width): keep it
   inside the content column, as compact buttons that wrap. Override of Carlos's CSS. */
.cc-app .admin-section-picker {
  left: auto; transform: none; width: 100%; max-width: none;
}
.cc-app .admin-section-picker .admin-section-buttons {
  display: flex; flex-wrap: wrap; gap: 8px;
}
.cc-app .admin-section-buttons button {
  width: auto; flex: 0 1 auto; min-height: 44px; padding: 9px 14px;
}
