/* DS-CG · Modèles de pages v1.3
   Mises en page des pages d'exemple (tableau de bord, vitrine, formulaire,
   article, connexion, parcours types). À charger après assets/ds-cg.css.
   Ce fichier n'est pas dans ds-cg.css : copiez seulement les parties du
   modèle que vous reprenez. Toutes les classes commencent par « tpl- ». */

/* ── Cadre commun ─────────────────────────────────────────── */

/* Barre d'évitement : repliée au repos (liens toujours atteignables au Tab),
   elle s'ouvre dans le flux dès qu'un de ses liens a le focus et pousse l'en-tête vers le bas.
   Liens : Contenu, Navigation, Pieds de page (seulement ceux qui existent sur la page). */
.tpl-skip { height: 0; overflow: hidden; background: var(--bg-subtle); }
.tpl-skip:focus-within { height: auto; overflow: visible; border-bottom: 1px solid var(--border); }
.tpl-skip__inner {
  max-width: var(--container);
  margin-inline: auto;
  padding: var(--space-2) var(--gutter);
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1) var(--space-2);
}
.tpl-skip a {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  padding: 0 var(--space-3);
  border-radius: var(--r-sm);
  font-size: 14px;
  font-weight: 500;
  color: var(--accent-text);
}
.tpl-skip a:focus-visible { text-decoration: underline; text-underline-offset: 3px; }
/* Navigation : le menu en grand écran ; sous 768 px, quand le script replie le menu, son bouton */
.tpl-skip .tpl-skip__menu { display: none; }
@media (max-width: 767px) {
  body:has(.topnav[data-js], .tpl-side[data-js]) .tpl-skip .tpl-skip__nav { display: none; }
  body:has(.topnav[data-js], .tpl-side[data-js]) .tpl-skip .tpl-skip__menu { display: inline-flex; }
}
/* Cibles atteintes par la barre : lues, sans anneau (ce ne sont pas des commandes) */
#navigation:focus, footer:focus { outline: none; }

.tpl-container {
  width: 100%;
  max-width: var(--container);
  margin-inline: auto;
  padding-inline: var(--gutter);
}

main:focus { outline: none; }

/* Pied de page collé en bas quand le contenu est court */
body:has(> main.tpl-page) {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
}
body:has(> main.tpl-page) > main.tpl-page { flex: 1 0 auto; }

/* Contenu court (page introuvable, confirmation) : centré verticalement */
main.tpl-page:has(> .tpl-container > .tpl-narrow) {
  display: flex;
  flex-direction: column;
  justify-content: center;
}

/* Titre de bloc dans une carte : niveau 2 pour la structure, taille de texte courant */
.tpl-panel-title {
  margin: 0;
  font: 600 16px/24px var(--font-sans);
  letter-spacing: 0;
}

/* En-tête de page : H1 à gauche, une action principale à droite */
.tpl-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4) var(--space-5);
}
.tpl-head h1 { margin: 0; }
.tpl-head p { margin: var(--space-1) 0 0; color: var(--text-muted); }

/* ── Tableau de bord ──────────────────────────────────────── */

.tpl-app {
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr);
  min-height: 100vh;
  min-height: 100dvh;
}

.tpl-side {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
  height: 100vh;
  height: 100dvh;
  padding: var(--space-4) var(--space-3);
  border-right: 1px solid var(--border);
  background: var(--bg-subtle);
  overflow-y: auto;
}
.tpl-side__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  padding-left: var(--space-3);
}
.tpl-side__toggle { display: none; }
.tpl-side__menu { display: flex; flex: 1; flex-direction: column; gap: var(--space-5); }
.tpl-side__nav ul {
  display: grid;
  gap: 2px;
  margin: 0;
  padding: 0;
  list-style: none;
}
.tpl-side__nav a {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-height: 36px;
  padding: 0 var(--space-3);
  border-radius: var(--r-sm);
  color: var(--text-muted);
  font: 500 14px/20px var(--font-sans);
  text-decoration: none;
  transition: color var(--dur-fast) ease, background-color var(--dur-fast) ease;
}
.tpl-side__nav svg { width: 20px; height: 20px; flex: none; }
.tpl-side__nav a[aria-current="page"] {
  background: var(--surface);
  color: var(--text);
  box-shadow: inset 0 0 0 1px var(--border);
}
.tpl-side__nav a[aria-current="page"] svg { color: var(--accent-text); }
@media (hover: hover) {
  .tpl-side__nav a:hover { color: var(--text); background: color-mix(in srgb, var(--text) 6%, transparent); text-decoration: none; }
  .tpl-side__nav a[aria-current="page"]:hover { background: var(--surface); }
}
.tpl-side__nav a:active { color: var(--text); background: color-mix(in srgb, var(--text) 12%, transparent); text-decoration: none; }
.tpl-side__nav a[aria-current="page"],
.tpl-side__nav a[aria-current="page"]:active { background: var(--surface); cursor: default; }
.tpl-side__label {
  margin: 0 0 var(--space-2);
  padding-left: var(--space-3);
  font: 500 12px/16px var(--font-sans);
  letter-spacing: .02em;
  color: var(--text-muted);
}
.tpl-side__foot {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin-top: auto;
  padding: var(--space-3);
  border-top: 1px solid var(--border);
  font-size: 14px;
  line-height: 20px;
}
.tpl-side__foot p { margin: 0; }
.tpl-side__foot p span { display: block; color: var(--text-muted); }

.tpl-main {
  display: grid;
  align-content: start;
  gap: var(--space-6);
  min-width: 0;
  padding: var(--space-6);
}
.tpl-main > * { min-width: 0; }

.tpl-kpis {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-4);
  margin: 0;
  padding: 0;
  list-style: none;
}
.tpl-kpis .card > * + * { margin-top: 0; }
.tpl-kpis .kpi-value { margin: var(--space-1) 0 var(--space-2); }
.tpl-kpis .badge { white-space: normal; }
@media (min-width: 640px) { .tpl-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (min-width: 1024px) { .tpl-kpis { grid-template-columns: repeat(4, minmax(0, 1fr)); } }

.tpl-charts {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--space-4);
}
@media (min-width: 1024px) { .tpl-charts { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.tpl-charts .card,
.tpl-table-card { display: flex; flex-direction: column; gap: var(--space-4); min-width: 0; }
.tpl-charts .card > * + *,
.tpl-table-card > * + * { margin-top: 0; }
.tpl-charts .card-head,
.tpl-table-card .card-head { margin-bottom: 0; }

/* Graphique en barres verticales : une série, valeurs écrites sur les barres */
.tpl-bars {
  display: flex;
  align-items: flex-end;
  gap: var(--space-3);
  height: 180px;
  margin: 0;
  padding: 0 var(--space-1);
  list-style: none;
  border-bottom: 1px solid var(--border-strong);
  background-image: linear-gradient(var(--border) 1px, transparent 1px);
  background-size: 100% 45px;
  background-position: 0 0;
}
.tpl-bars li {
  display: flex;
  flex: 1;
  flex-direction: column;
  justify-content: flex-end;
  align-items: stretch;
  height: 100%;
  min-width: 0;
}
.tpl-bars__value {
  display: block;
  margin-bottom: var(--space-1);
  font: 500 12px/16px var(--font-sans);
  font-variant-numeric: tabular-nums;
  text-align: center;
  color: var(--text-muted);
}
.tpl-bars__bar {
  display: block;
  height: var(--h);
  border-radius: 4px 4px 0 0;
  background: var(--chart-1);
}
.tpl-bars li.is-current .tpl-bars__value { color: var(--text); font-weight: 600; }
.tpl-axis {
  display: flex;
  gap: var(--space-3);
  margin: 0;
  padding: var(--space-2) var(--space-1) 0;
  list-style: none;
  font-size: 12px;
  line-height: 16px;
  color: var(--text-muted);
}
.tpl-axis li { flex: 1; min-width: 0; text-align: center; }

/* Répartition : barres horizontales, libellé et valeur écrits */
.tpl-split {
  display: grid;
  gap: var(--space-4);
  margin: 0;
  padding: 0;
  list-style: none;
}
.tpl-split li { display: grid; gap: var(--space-2); }
.tpl-split__row {
  display: flex;
  justify-content: space-between;
  gap: var(--space-3);
  font-size: 14px;
  line-height: 20px;
}
.tpl-split__row span:last-child { font-variant-numeric: tabular-nums; color: var(--text-muted); }
.tpl-split__track {
  display: block;
  height: 8px;
  border-radius: var(--r-full);
  background: var(--bg-subtle);
  box-shadow: inset 0 0 0 1px var(--border);
  overflow: hidden;
}
.tpl-split__fill {
  display: block;
  width: var(--w);
  height: 100%;
  border-radius: var(--r-full);
  background: var(--c, var(--chart-1));
}

/* « Voir les données » sous un graphique */
.tpl-data summary {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  min-height: 44px;
  color: var(--accent-text);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  list-style: none;
}
.tpl-data summary::-webkit-details-marker { display: none; }
.tpl-data summary svg { width: 16px; height: 16px; transition: transform var(--dur-fast) var(--ease); }
.tpl-data[open] summary svg { transform: rotate(90deg); }
@media (hover: hover) { .tpl-data summary:hover { text-decoration: underline; text-underline-offset: 3px; } }
.tpl-data summary:active { color: var(--text); text-decoration: underline; text-decoration-thickness: 2px; text-underline-offset: 3px; }
.tpl-data .table-wrap { margin-top: var(--space-2); }

/* Tableau dans une carte : il va jusqu'aux bords */
.tpl-table-card .table-wrap {
  margin: 0 calc(var(--card-p) * -1) calc(var(--card-p) * -1);
  border: 0;
  border-top: 1px solid var(--border);
  border-radius: 0 0 var(--r-md) var(--r-md);
}

/* Sous 768 px : la barre latérale devient une barre du haut avec un menu */
@media (max-width: 767px) {
  .tpl-app { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto 1fr; }
  .tpl-side {
    z-index: 20;
    height: auto;
    padding: var(--space-2) var(--space-2) var(--space-2) var(--space-1);
    border-right: 0;
    border-bottom: 1px solid var(--border);
    overflow: visible;
  }
  .tpl-side__toggle { display: inline-flex; }
  .tpl-side__toggle .icon-close { display: none; }
  .tpl-side__toggle[aria-expanded="true"] .icon-open { display: none; }
  .tpl-side__toggle[aria-expanded="true"] .icon-close { display: block; }
  .tpl-side__menu {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    max-height: calc(100dvh - 60px);
    padding: var(--space-4) var(--space-3);
    border-bottom: 1px solid var(--border);
    background: var(--bg-subtle);
    box-shadow: var(--shadow-1);
    overflow-y: auto;
  }
  .tpl-side[data-js] .tpl-side__menu:not([data-open]) { display: none; }
  .tpl-side__nav a { min-height: 44px; }
  .tpl-main { gap: var(--space-5); padding: var(--space-5) var(--gutter); }
}

/* ── Page vitrine ─────────────────────────────────────────── */

.tpl-section { padding-block: var(--space-10); }
.tpl-section + .tpl-section { padding-top: 0; }
.tpl-section > .tpl-container > h2 { margin: 0 0 var(--space-2); }
.tpl-section__intro { max-width: 560px; margin: 0 0 var(--space-7); color: var(--text-muted); }

.tpl-hero {
  display: grid;
  gap: var(--space-7);
  align-items: center;
}
.tpl-hero h1 { margin: 0; }
.tpl-hero .ds-lead { max-width: 560px; margin: var(--space-5) 0 0; }
.tpl-hero__actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  margin-top: var(--space-6);
}
.tpl-hero__media {
  margin: 0;
  border-radius: var(--r-lg);
  overflow: hidden;
  background: var(--bg-subtle);
}
.tpl-hero__media svg { display: block; width: 100%; height: auto; }
@media (min-width: 1024px) {
  .tpl-hero { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: var(--space-8); }
}

.tpl-features {
  display: grid;
  gap: var(--space-7) var(--space-6);
  margin: 0;
  padding: 0;
  list-style: none;
}
.tpl-features svg { width: 24px; height: 24px; color: var(--accent-text); }
.tpl-features h3 { margin: var(--space-4) 0 var(--space-2); }
.tpl-features p { margin: 0; color: var(--text-muted); }
@media (min-width: 768px) { .tpl-features { grid-template-columns: repeat(3, minmax(0, 1fr)); } }

/* Annonces : image 4:3, badge en haut à gauche */
.tpl-listing { position: relative; }
.tpl-listing .card-media { aspect-ratio: 4 / 3; }
.tpl-listing .badge {
  position: absolute;
  top: var(--space-3);
  left: var(--space-3);
  z-index: 1;
}
.tpl-listing svg.card-media { height: auto; color: var(--text-faint); }

.tpl-band {
  display: grid;
  justify-items: center;
  gap: var(--space-4);
  padding: var(--space-8) var(--space-5);
  border-radius: var(--r-lg);
  background: var(--bg-subtle);
  text-align: center;
}
.tpl-band h2, .tpl-band p { margin: 0; }
.tpl-band p { max-width: 520px; color: var(--text-muted); }
.tpl-band .btn { margin-top: var(--space-2); }

@media (max-width: 767px) {
  .tpl-section { padding-block: 80px; }
  .tpl-band { padding: var(--space-7) var(--space-5); }
}

/* ── Formulaire ───────────────────────────────────────────── */

.tpl-page { padding-block: var(--space-7) var(--space-9); }

.tpl-form { max-width: 560px; margin-inline: auto; }
.tpl-form > h1 { margin: 0; }
.tpl-form__intro { margin: var(--space-3) 0 0; color: var(--text-muted); }
.tpl-back {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  min-height: 44px;
  margin-bottom: var(--space-4);
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 500;
}
.tpl-back svg { width: 16px; height: 16px; }
@media (hover: hover) { .tpl-back:hover { color: var(--text); } }
.tpl-back:active { color: var(--text); text-decoration: underline; text-decoration-thickness: 2px; }

.tpl-form form { margin-top: var(--space-7); }
.tpl-form .error-summary { margin-bottom: var(--space-7); }
.tpl-group {
  display: grid;
  gap: var(--space-5);
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}
.tpl-group + .tpl-group { margin-top: var(--space-7); }
.tpl-group > legend {
  float: left;
  width: 100%;
  margin: 0 0 var(--space-5);
  padding: 0;
  font: 600 20px/28px var(--font-sans);
  letter-spacing: -.01em;
}
.tpl-group > legend + * { clear: both; }
.tpl-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-3) var(--space-5);
  margin-top: var(--space-7);
}
.tpl-actions a { font-weight: 500; display: inline-flex; align-items: center; min-height: 44px; }
@media (max-width: 479px) {
  .tpl-actions { flex-direction: column; align-items: stretch; }
  .tpl-actions .btn { width: 100%; }
  .tpl-actions a:not(.btn) { justify-content: center; }
  /* Formulaire long sur téléphone : le bouton reste à portée du pouce, en bas de l'écran */
  .tpl-form .tpl-actions {
    position: sticky;
    bottom: 0;
    z-index: 1;
    gap: 0;
    margin-inline: calc(-1 * var(--gutter));
    padding: var(--space-3) var(--gutter) max(var(--space-2), env(safe-area-inset-bottom));
    background: var(--bg);
    border-top: 1px solid var(--border);
  }
  /* Le champ qui reçoit le focus ne passe jamais sous la barre */
  html:has(.tpl-form .tpl-actions) { scroll-padding-bottom: 128px; }
}
.tpl-form .help .sr-only { position: absolute; }

/* ── Article ──────────────────────────────────────────────── */

.tpl-article { max-width: var(--reading); margin-inline: auto; }
.tpl-article .breadcrumb { margin-bottom: var(--space-6); }
.tpl-article h1 { margin: 0; }
.tpl-article__meta {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1) var(--space-4);
  margin: var(--space-4) 0 0;
  padding: 0;
  list-style: none;
  font-size: 14px;
  line-height: 22px;
  color: var(--text-muted);
}
.tpl-article__lead { margin: var(--space-6) 0 0; font-size: 19px; line-height: 30px; }
.tpl-prose { margin-top: var(--space-6); line-height: 26px; }
.tpl-prose > * { margin: 0; }
.tpl-prose > * + * { margin-top: var(--space-4); }
.tpl-prose > h2 { margin-top: var(--space-7); }
.tpl-prose > h3 { margin-top: var(--space-6); }
.tpl-prose > h2 + *, .tpl-prose > h3 + * { margin-top: var(--space-3); }
.tpl-prose a { text-decoration: underline; text-underline-offset: 3px; }
.tpl-prose ul { padding-left: var(--space-5); }
.tpl-prose li + li { margin-top: var(--space-2); }
.tpl-prose figure { margin-block: var(--space-7); }
.tpl-prose figure + * { margin-top: 0; }
.tpl-prose figure svg { display: block; width: 100%; height: auto; border-radius: var(--r-md); }
.tpl-prose figcaption {
  margin-top: var(--space-3);
  font-size: 14px;
  line-height: 22px;
  color: var(--text-muted);
}
.tpl-related { margin-top: var(--space-9); padding-top: var(--space-7); border-top: 1px solid var(--border); }
.tpl-related h2 { margin: 0 0 var(--space-5); }
.tpl-related .card-grid { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.tpl-related .card h3 { font-size: 16px; line-height: 24px; }

/* ── Connexion ────────────────────────────────────────────── */

.tpl-auth-page { background: var(--bg-subtle); }
.tpl-auth {
  display: grid;
  justify-items: center;
  align-content: center;
  gap: var(--space-5);
  min-height: 100vh;
  min-height: 100dvh;
  padding: var(--space-7) var(--gutter);
}
.tpl-auth .logo { font-size: 20px; }
.tpl-auth__card {
  width: 100%;
  max-width: 400px;
  padding: var(--space-6);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  background: var(--surface);
}
.tpl-auth__card h1 { margin: 0 0 var(--space-5); font-size: 28px; line-height: 34px; }
.tpl-auth__card form { display: grid; gap: var(--space-5); }
.tpl-auth__card .error-summary { margin-bottom: 0; }
.tpl-auth__switch { margin: 0; font-size: 15px; text-align: center; color: var(--text-muted); }
.tpl-auth__forgot { justify-self: start; margin-top: calc(var(--space-2) * -1); font-size: 14px; font-weight: 500; }

@media (max-width: 479px) {
  .tpl-auth { align-content: start; padding-top: var(--space-6); }
  .tpl-auth__card { padding: var(--space-5); }
}

/* ── Parcours : page introuvable, confirmation ───────────── */

.tpl-narrow { max-width: 640px; margin-inline: auto; }
.tpl-narrow h1 { margin: 0; }
.tpl-narrow > p { margin: var(--space-4) 0 0; }
.tpl-links {
  display: grid;
  gap: var(--space-2);
  margin: var(--space-6) 0 0;
  padding: 0;
  list-style: none;
}
.tpl-links a {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  min-height: 44px;
  font-weight: 500;
}
.tpl-links svg { width: 20px; height: 20px; }

/* ── Illustrations des exemples (SVG en ligne, suivent le thème) ── */

.tpl-art .sky { fill: var(--bg-subtle); }
.tpl-art .ground { fill: var(--bg-subtle); }
.tpl-art .wall { fill: var(--surface); stroke: var(--border-strong); stroke-width: 1.5; }
.tpl-art .wall-alt { fill: var(--bg-subtle); stroke: var(--border-strong); stroke-width: 1.5; }
.tpl-art .win { fill: var(--accent-soft); stroke: var(--border-strong); stroke-width: 1.5; }
.tpl-art .roof { fill: var(--border); }
.tpl-art .sun { fill: var(--chart-2); }
.tpl-art .door { fill: var(--chart-1); }
.tpl-art .tree { fill: var(--success); opacity: .55; }

/* Formulaire refusé : le texte d'aide garde sa couleur, seul le message d'erreur passe en rouge */
.tpl-form .field.error .help:not(.tpl-err) { color: var(--text-muted); }
.tpl-err { font-weight: 500; }
.tpl-err[hidden] { display: none; }

/* Parcours types v1.3 */
.tpl-empty-page { margin-top: var(--space-9); padding-top: 0; }
.tpl-row-actions { white-space: nowrap; text-align: right; }
.tpl-row-actions .btn + .btn { margin-left: var(--space-1); }
@media (max-width: 767px) {
  .tpl-empty-page { margin-top: var(--space-7); }
}
.table-wrap[hidden] { display: none; }
