/*
 * LE VERRE DE L'APPLICATION SUR LES PAGES STATIQUES — mentions légales, confidentialité, continuité,
 * conditions de l'API (`public/*.html`) et le portail développeurs (`public/developers/`, servi aussi
 * sur developers.myleapp.fr : `DEVELOPERS_SHARED` de `server.mjs`).
 *
 * Chargée APRÈS la feuille de chaque page : elle ne fait que repeindre leurs classes communes
 * (`.nav`, `.page-header`, `.content-container` / `.doc`, `.footer`…). Les valeurs viennent du
 * système A de l'app :
 *   - le fond à halos : `liquidGlass.canvas` (`src/theme/foundations/semanticTokens.ts`) ;
 *   - la matière : `A_GLASS` (`appleSystemColors.ts` : blanc à 0,42 / 0,62 menu / 0,8 feuille en clair,
 *     gris 28 28 30 à 0,48 / 0,6 / 0,74 en sombre), `A_GLASS_FILL`, `aGlassRim`, `--a-glass-shadow` (`glassA.ts`).
 * Pas de réfraction (le filtre SVG de `LiquidGlass`) : ici le repli de l'app, le dépoli. Les grandes
 * surfaces de texte (la feuille) n'ont pas de `backdrop-filter` : derrière elles le fond est un dégradé
 * lisse, le flou n'y verrait rien et coûterait à chaque défilement.
 *
 * LE MODE SOMBRE suit le système (`prefers-color-scheme`). Les pages nomment leurs couleurs par des
 * échelles (`--gray-*` / `--brand-*` au portail, `--color-gray-*` / `--color-brand-*` aux pages
 * légales) : en sombre, ces échelles sont retournées (le 50 devient le plus foncé…). Ce qui est
 * sombre par dessein — le pied de page, les blocs de code — reprend les valeurs claires d'origine,
 * pour rester tel quel.
 *
 * LES MENUS : la capsule de l'en-tête a, sous elle et au-dessus d'elle, un bandeau du fond de page
 * (`.nav::before`) : le texte qui défile disparaît dessous au lieu de passer autour de la capsule.
 * Sur petit écran, un menu hamburger : celui des pages légales (leur bouton `.mobile-menu-btn`, ouvert
 * jusqu'à 1024 px au lieu de 768, les liens ne tenaient pas entre les deux) ; celui du portail
 * (`.nav-menu`, un `<details>` écrit par `developers-layout.py`, sans script : CSP `script-src 'self'`).
 */
:root {
  --g-canvas: radial-gradient(900px 640px at 0% 0%, rgba(163, 230, 53, 0.24), transparent 64%),
    radial-gradient(700px 520px at 0% 100%, rgba(125, 211, 252, 0.2), transparent 62%),
    radial-gradient(900px 700px at 100% 100%, rgba(196, 181, 253, 0.14), transparent 60%), #eaecf0;
  --g-base: #eaecf0;
  --g-tint: 255 255 255;
  --g-clear: 0.42;
  --g-menu: 0.62;
  --g-sheet-tint: 255 255 255;
  --g-sheet: 0.8;
  --g-blur: blur(12px) saturate(170%);
  --g-shadow: inset 0 1px 1px rgba(255, 255, 255, 0.45), inset 0 -10px 18px -14px rgba(255, 255, 255, 0.55),
    0 8px 22px -10px rgba(0, 0, 0, 0.28);
  --g-sheet-shadow: inset 0 1px 1px rgba(255, 255, 255, 0.6), 0 1px 2px rgba(0, 0, 0, 0.04),
    0 18px 40px -24px rgba(15, 23, 42, 0.28);
  --g-rim: linear-gradient(135deg, rgba(255, 255, 255, 0.95) 0%, rgba(255, 255, 255, 0.18) 26%,
    rgba(255, 255, 255, 0) 48%, rgba(255, 255, 255, 0.1) 70%, rgba(255, 255, 255, 0.6) 100%);
  --g-pill: rgb(255 255 255 / 0.8);
  --g-pill-shadow: inset 0 1px 1px rgba(255, 255, 255, 0.8), 0 0 0 0.5px rgba(0, 0, 0, 0.06),
    0 4px 12px -8px rgba(0, 0, 0, 0.3);
  --g-hover: rgb(255 255 255 / 0.5);
  --g-card: radial-gradient(130% 150% at 50% 50%, rgb(255 255 255 / 0.9) 42%, rgb(255 255 255 / 0.6) 100%);
  --g-card-hover: radial-gradient(130% 150% at 50% 50%, rgb(255 255 255) 42%, rgb(240 255 244 / 0.8) 100%);
  --g-note: linear-gradient(135deg, rgba(198, 246, 213, 0.55), rgba(240, 255, 244, 0.7));
  --g-note-edge: rgba(56, 161, 105, 0.18);
  --g-coming: linear-gradient(135deg, rgba(253, 230, 138, 0.45), rgba(255, 251, 235, 0.75));
  --g-coming-edge: rgba(217, 119, 6, 0.2);
  --g-inset: inset 0 1px 1px rgba(255, 255, 255, 0.8);
  --g-th: rgb(241 245 249 / 0.7);
  --g-menu-solid: #fafbfc;
  --g-ink: #334155;
  --g-green: 47 133 90;
  --g-green-hover: 39 103 73;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --g-canvas: radial-gradient(1100px 620px at 0% 0%, rgba(132, 204, 22, 0.1), transparent 62%),
      radial-gradient(900px 700px at 100% 100%, rgba(56, 189, 248, 0.08), transparent 60%), #14171d;
    --g-base: #14171d;
    --g-tint: 28 28 30;
    --g-clear: 0.48;
    --g-menu: 0.6;
    --g-sheet-tint: 30 34 42;
    --g-sheet: 0.78;
    --g-shadow: inset 0 1px 1px rgba(255, 255, 255, 0.18), inset 0 -10px 18px -14px rgba(255, 255, 255, 0.2),
      0 8px 22px -10px rgba(0, 0, 0, 0.6);
    --g-sheet-shadow: inset 0 1px 1px rgba(255, 255, 255, 0.08), 0 18px 40px -22px rgba(0, 0, 0, 0.7);
    --g-rim: linear-gradient(135deg, rgba(255, 255, 255, 0.24) 0%, rgba(255, 255, 255, 0.06) 26%,
      rgba(255, 255, 255, 0) 48%, rgba(255, 255, 255, 0.04) 70%, rgba(255, 255, 255, 0.14) 100%);
    --g-pill: rgb(255 255 255 / 0.12);
    --g-pill-shadow: inset 0 1px 1px rgba(255, 255, 255, 0.12), 0 0 0 0.5px rgba(255, 255, 255, 0.06),
      0 4px 12px -8px rgba(0, 0, 0, 0.6);
    --g-hover: rgb(255 255 255 / 0.07);
    --g-card: radial-gradient(130% 150% at 50% 50%, rgb(44 50 62 / 0.9) 42%, rgb(36 41 52 / 0.7) 100%);
    --g-card-hover: radial-gradient(130% 150% at 50% 50%, rgb(52 60 74) 42%, rgb(36 58 46 / 0.85) 100%);
    --g-note: linear-gradient(135deg, rgba(56, 161, 105, 0.2), rgba(56, 161, 105, 0.1));
    --g-note-edge: rgba(104, 211, 145, 0.22);
    --g-coming: linear-gradient(135deg, rgba(217, 119, 6, 0.22), rgba(217, 119, 6, 0.1));
    --g-coming-edge: rgba(245, 158, 11, 0.28);
    --g-inset: inset 0 1px 1px rgba(255, 255, 255, 0.08);
    --g-th: rgb(255 255 255 / 0.05);
    --g-menu-solid: #1f232b;
    --g-ink: #cdd3dc;
    /* Le vert des boutons à texte blanc reste celui du clair : plus clair, le blanc n'y tiendrait plus 4,5:1. */
    --g-green: 47 133 90;
    --g-green-hover: 39 103 73;
    color-scheme: dark;

    /* Les échelles des pages, retournées. Portail : */
    --gray-50: #161a21;
    --gray-100: #1f242d;
    --gray-200: #2d3440;
    --gray-300: #3f4756;
    --gray-400: #7c8698;
    --gray-500: #98a2b3;
    --gray-600: #b4bcc8;
    --gray-700: #cdd3dc;
    --gray-800: #e2e6ec;
    --gray-900: #f1f4f8;
    --brand-50: rgba(56, 161, 105, 0.14);
    --brand-100: #1f4d33;
    --brand-200: #2f6b4a;
    --brand-500: #48bb78;
    --brand-600: #68d391;
    --brand-700: #9ae6b4;
    --brand-900: #c6f6d5;
    --amber-50: rgba(217, 119, 6, 0.14);
    --amber-500: #f59e0b;
    /* … pages légales : */
    --color-gray-50: #161a21;
    --color-gray-100: #1f242d;
    --color-gray-200: #2d3440;
    --color-gray-300: #3f4756;
    --color-gray-400: #7c8698;
    --color-gray-500: #98a2b3;
    --color-gray-600: #b4bcc8;
    --color-gray-700: #cdd3dc;
    --color-gray-800: #e2e6ec;
    --color-gray-900: #f1f4f8;
    --color-brand-50: rgba(56, 161, 105, 0.14);
    --color-brand-100: #1f4d33;
    --color-brand-200: #2f6b4a;
    --color-brand-500: #48bb78;
    --color-brand-600: #68d391;
    --color-brand-700: #9ae6b4;
    --color-accent: #48bb78;
  }

  /* Sombres par dessein : ils gardent les valeurs claires d'origine. */
  .footer,
  .doc pre,
  .doc .example {
    --gray-100: #f1f5f9;
    --gray-200: #e2e8f0;
    --gray-300: #cbd5e1;
    --gray-400: #94a3b8;
    --gray-500: #64748b;
    --gray-600: #475569;
    --gray-700: #334155;
    --gray-800: #1e293b;
    --gray-900: #0f172a;
    --brand-200: #9ae6b4;
    --brand-500: #38a169;
    --color-gray-300: #cbd5e1;
    --color-gray-400: #94a3b8;
    --color-gray-800: #1e293b;
  }

  /* Un lien laissé à la couleur du navigateur (les pages légales en ont) : lisible sur le sombre. */
  .content-container a:not([class]),
  .doc a:not([class]) {
    color: #68d391;
  }

  /* Pages légales : le badge « en cours » de la continuité. */
  .status-wip {
    background: rgba(217, 119, 6, 0.16);
    color: #fbbf24;
    border-color: rgba(245, 158, 11, 0.35);
  }

  /* Le logo de Myle (vert foncé) : un liseré clair pour le détacher du fond. */
  .logo-icon,
  .logo img {
    box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.12);
    border-radius: 8px;
  }

  .mobile-menu-btn span {
    background: var(--g-ink);
  }

  /* Portail, référence : « Utiliser mon compte Myle » (texte blanc sur le vert de l'échelle, retournée). */
  .reference-connect-button {
    background: rgb(var(--g-green));
    border-color: rgb(var(--g-green));
  }

  .reference-connect-button:hover {
    background: rgb(var(--g-green-hover));
  }
}

/* ── Le fond ─────────────────────────────────────────────────────────────────────────────── */

html {
  background: var(--g-base);
}

body {
  background: none;
}

/* Le fond sur un calque fixe plutôt qu'en `background-attachment: fixed`, qu'iOS ignore et qui
   repeint toute la page à chaque défilement ailleurs. */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: -1;
  background: var(--g-canvas);
  pointer-events: none;
}

/* ── La matière : un fond qui laisse passer, un liseré clair, une ombre douce ──────────────── */

.nav-container,
.content-container,
.doc,
.cards a,
.section-nav a,
.nav-links .lang,
.toc,
.footer {
  position: relative;
  isolation: isolate;
}

/* Collante en grand écran (elle porte donc déjà son liseré) ; statique sous 960 px, voir plus bas. */
.sidebar {
  isolation: isolate;
}

.nav-container::after,
.sidebar::after,
.content-container::after,
.doc::after,
.cards a::after,
.section-nav a::after,
.toc::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  padding: 1px;
  background: var(--g-rim);
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
  mask: linear-gradient(#000 0 0) content-box exclude, linear-gradient(#000 0 0);
}

/* ── L'en-tête : une capsule de verre qui flotte au-dessus de la page ─────────────────────── */

.nav {
  background: none;
  border-bottom: 0;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  padding: 0.75rem 1rem;
  /* Autour de la capsule, la page reste cliquable. */
  pointer-events: none;
}

/* Le bandeau du fond de page derrière la capsule : le texte qui défile passe dessous et disparaît,
   au lieu de rester lisible au-dessus et autour d'elle. Le même fond que la page (attaché à l'écran),
   fondu sur son dernier centimètre pour ne pas tracer de trait. */
.nav::before {
  content: '';
  position: absolute;
  inset: 0 0 -1rem;
  z-index: -1;
  background: var(--g-canvas);
  background-attachment: fixed;
  -webkit-mask-image: linear-gradient(#000 calc(100% - 1.5rem), transparent);
  mask-image: linear-gradient(#000 calc(100% - 1.5rem), transparent);
}

.nav-container {
  pointer-events: auto;
  border-radius: 22px;
  padding: 0.55rem 0.6rem 0.55rem 1.1rem;
  background: radial-gradient(130% 150% at 50% 50%, rgb(var(--g-tint) / var(--g-menu)) 42%,
    rgb(var(--g-tint) / calc(var(--g-menu) * 0.7)) 100%);
  box-shadow: var(--g-shadow);
  backdrop-filter: var(--g-blur);
  -webkit-backdrop-filter: var(--g-blur);
}

.nav-links .lang {
  border: 0;
  background: var(--g-pill);
  box-shadow: var(--g-pill-shadow);
}

/* L'action principale : le vert de la marque, en verre teinté. */
.nav-cta {
  border-radius: 999px !important;
  background: linear-gradient(180deg, rgb(var(--g-green) / 0.92), rgb(var(--g-green)) 100%) !important;
  box-shadow: inset 0 1px 1px rgba(255, 255, 255, 0.45), inset 0 -8px 14px -12px rgba(255, 255, 255, 0.5),
    0 8px 22px -12px rgb(var(--g-green) / 0.7);
}

.nav-cta:hover {
  background: linear-gradient(180deg, rgb(var(--g-green-hover) / 0.92), rgb(var(--g-green-hover))) !important;
}

/* ── Le titre de page : posé sur le fond, sans bandeau ────────────────────────────────────── */

.page-header {
  background: none;
}

.section-nav a {
  border: 0;
  background: rgb(var(--g-tint) / var(--g-clear));
  box-shadow: var(--g-shadow);
  backdrop-filter: var(--g-blur);
  -webkit-backdrop-filter: var(--g-blur);
}

.section-nav a:hover {
  background: rgb(var(--g-tint) / var(--g-menu));
}

/* ── La feuille de texte ──────────────────────────────────────────────────────────────────── */

.content-container,
.doc {
  border-radius: 28px;
  background: radial-gradient(140% 140% at 50% 35%, rgb(var(--g-sheet-tint) / var(--g-sheet)) 55%,
    rgb(var(--g-sheet-tint) / calc(var(--g-sheet) * 0.86)) 100%);
  box-shadow: var(--g-sheet-shadow);
}

/* La liste des guides, à gauche : un panneau de verre, la page courante en pastille. */
.sidebar {
  border-radius: 22px;
  padding: 1rem 0.6rem 0.4rem;
  background: rgb(var(--g-tint) / var(--g-clear));
  box-shadow: var(--g-shadow);
  backdrop-filter: var(--g-blur);
  -webkit-backdrop-filter: var(--g-blur);
}

.sidebar h2 {
  padding: 0 0.65rem;
}

.sidebar ol,
.sidebar ul {
  margin-bottom: 0.75rem;
}

.sidebar li a {
  border-left: 0;
  border-radius: 12px;
  padding: 0.35rem 0.65rem;
}

.sidebar li a:hover {
  background: var(--g-hover);
}

.sidebar li a[aria-current='page'] {
  background: var(--g-pill);
  box-shadow: var(--g-pill-shadow);
}

/* Les tuiles des guides. */
.cards a {
  border: 0;
  border-radius: 20px;
  background: var(--g-card);
  box-shadow: var(--g-shadow);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.cards a:hover {
  background: var(--g-card-hover);
  transform: translateY(-1px);
}

/* Encadrés : un verre teinté, plus de trait à gauche. */
.note,
.contact-box {
  border-left: 0;
  border-radius: 18px;
  background: var(--g-note);
  box-shadow: var(--g-inset), inset 0 0 0 1px var(--g-note-edge);
}

.note.coming {
  background: var(--g-coming);
  box-shadow: var(--g-inset), inset 0 0 0 1px var(--g-coming-edge);
}

.toc {
  border: 0;
  border-radius: 18px;
  background: var(--g-hover);
  box-shadow: var(--g-pill-shadow);
}

/* Les tableaux : l'en-tête en verre plutôt qu'en aplat. */
.doc th,
.data-table th {
  background: var(--g-th);
}

.doc pre {
  border-radius: 14px;
}

.doc .example {
  border-radius: 14px;
}

/* ── Le pied de page : un verre fumé qui flotte ───────────────────────────────────────────── */

.footer {
  /* `auto` en haut : sur une page courte (corps en colonne flex, portail), il reste en bas de l'écran. */
  margin: auto 1rem 1rem;
  border-radius: 28px;
  background: linear-gradient(180deg, rgba(20, 23, 29, 0.9), rgba(15, 23, 42, 0.94));
  box-shadow: inset 0 1px 1px rgba(255, 255, 255, 0.12), 0 18px 40px -20px rgba(0, 0, 0, 0.45);
}

/* ── Le menu hamburger du portail (`.nav-menu`, écrit par `developers-layout.py`) ─────────── */

.nav-menu {
  display: none;
  position: static;
}

.nav-menu > summary {
  list-style: none;
  display: grid;
  place-items: center;
  width: 2.75rem;
  height: 2.75rem;
  border-radius: 999px;
  cursor: pointer;
  color: var(--g-ink);
}

.nav-menu > summary::-webkit-details-marker {
  display: none;
}

.nav-menu > summary:hover {
  background: var(--g-hover);
}

.nav-menu > summary:focus-visible {
  outline: 2px solid rgb(var(--g-green));
  outline-offset: 2px;
}

/* Trois traits, une croix quand le menu est ouvert. */
.nav-menu-icon,
.nav-menu-icon::before,
.nav-menu-icon::after {
  display: block;
  width: 20px;
  height: 2px;
  border-radius: 2px;
  background: currentColor;
  transition: transform 0.2s ease, opacity 0.2s ease;
}

.nav-menu-icon {
  position: relative;
}

.nav-menu-icon::before,
.nav-menu-icon::after {
  content: '';
  position: absolute;
  left: 0;
}

.nav-menu-icon::before {
  top: -6px;
}

.nav-menu-icon::after {
  top: 6px;
}

.nav-menu[open] .nav-menu-icon {
  background: transparent;
}

.nav-menu[open] .nav-menu-icon::before {
  transform: translateY(6px) rotate(45deg);
  background: currentColor;
}

.nav-menu[open] .nav-menu-icon::after {
  transform: translateY(-6px) rotate(-45deg);
  background: currentColor;
}

/* Le menu ouvert : plein (posé dans la capsule, qui a déjà son propre flou, son flou à lui ne
   verrait que la capsule, pas la page dessous). */
.nav-menu-links,
.nav-container:has(.mobile-menu-btn) .nav-links.active {
  border-radius: 20px;
  background: var(--g-menu-solid);
  box-shadow: var(--g-shadow), 0 0 0 0.5px rgba(127, 127, 127, 0.2);
}

.nav-menu-links {
  position: absolute;
  top: calc(100% + 0.5rem);
  left: 0;
  right: 0;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  padding: 0.6rem;
}

.nav-menu-links a {
  display: block;
  padding: 0.7rem 0.9rem;
  border-radius: 14px;
  color: var(--g-ink);
  text-decoration: none;
  font-weight: 500;
}

.nav-menu-links a:hover,
.nav-menu-links a[aria-current='page'] {
  background: var(--g-hover);
  color: var(--brand-600, #2f855a);
}

.nav-menu-links .nav-cta {
  margin-top: 0.35rem;
  text-align: center;
  color: white !important;
}

@media (max-width: 960px) {
  .sidebar {
    position: relative;
  }
}

/* Portail : sous 880 px les six liens ne tiennent plus sur la capsule, le hamburger les prend. */
@media (max-width: 880px) {
  .nav-container:has(.nav-menu) {
    flex-direction: row !important;
    align-items: center !important;
    padding: 0.45rem 0.45rem 0.45rem 1rem;
  }

  .nav-container:has(.nav-menu) > .nav-links {
    display: none;
  }

  .nav-menu {
    display: block;
  }
}

/* Pages légales : leur hamburger (bouton `.mobile-menu-btn`, script de la page) jusqu'à 1024 px. */
@media (max-width: 1024px) {
  .nav-container:has(.mobile-menu-btn) .nav-links {
    display: none;
    position: absolute;
    top: calc(100% + 0.5rem);
    left: 0;
    right: 0;
    flex-direction: column;
    gap: 0.25rem;
    padding: 0.75rem;
    border: 0;
  }

  .nav-container:has(.mobile-menu-btn) .nav-links.active {
    display: flex;
  }

  .nav-container:has(.mobile-menu-btn) .nav-links a:not(.nav-cta) {
    padding: 0.6rem 0.9rem;
    border-radius: 14px;
  }

  .nav-container:has(.mobile-menu-btn) .nav-links a:not(.nav-cta):hover {
    background: var(--g-hover);
  }

  .nav-container:has(.mobile-menu-btn) .nav-links .nav-cta {
    text-align: center;
    margin-top: 0.35rem;
  }

  .nav-container:has(.mobile-menu-btn) .mobile-menu-btn {
    display: flex;
    padding: 0.6rem;
  }

  /* La capsule porte son menu : elle ne le coupe pas. */
  .nav-container {
    isolation: auto;
  }
}

@media (max-width: 640px) {
  /* La capsule du portail : de l'air des deux côtés. */
  .nav-container {
    padding: 0.45rem 0.45rem 0.45rem 1rem;
  }

  .content-container,
  .doc {
    border-radius: 22px;
  }

  .footer {
    margin: auto 0.5rem 0.5rem;
    border-radius: 22px;
  }
}

/* Sans transparence demandée par le système : des surfaces pleines. */
@media (prefers-reduced-transparency: reduce) {
  .nav-container,
  .sidebar,
  .section-nav a,
  .cards a,
  .toc,
  .nav-links .lang {
    background: var(--g-menu-solid);
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }

  .content-container,
  .doc {
    background: var(--g-menu-solid);
  }

  .note,
  .contact-box {
    background: var(--brand-50, #f0fff4);
  }

  .note.coming {
    background: var(--amber-50, #fffbeb);
  }
}
