/*
 * Blocs dynamiques du contenu des teasers (HTML saisi dans l'éditeur du back-office).
 * Chargé par les pages de teaser uniquement (bloc additional_css de layout.html.twig).
 *
 * Catalogue :
 *   .ax-switch   volets exclusifs : <details name="..."> dont un seul reste ouvert
 *   .ax-chart    graphique Chart.js et sa légende (voir controllers/teaser_widgets.js)
 *   .ax-anim-*   animations d'apparition, coupées si le visiteur demande moins de mouvement
 */

@keyframes ax-fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes ax-slide-up {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: none; }
}

.ax-anim-fade-in { animation: ax-fade-in 0.6s ease-out both; }
.ax-anim-slide-up { animation: ax-slide-up 0.6s ease-out both; }

/* Apparition au défilement, sans JavaScript : ignorée par les navigateurs qui ne savent pas faire. */
@supports (animation-timeline: view()) {
  .ax-anim-on-scroll {
    animation: ax-slide-up linear both;
    animation-timeline: view();
    animation-range: entry 0% entry 35%;
  }
}

@media (prefers-reduced-motion: reduce) {
  .ax-anim-fade-in,
  .ax-anim-slide-up,
  .ax-anim-on-scroll {
    animation: none;
  }
}

/* Volets exclusifs : des boutons en ligne, le volet ouvert s'affiche dessous. */
.ax-switch {
  --ax-switch-bg: #fefaf5;
  --ax-switch-border: #f8ebd6;
  --ax-switch-active: #042339;
  margin: 0 0 24px;
}

.ax-switch > details {
  margin: 0 0 12px;
}

.ax-switch > details > summary {
  display: flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  min-height: 56px;
  padding: 12px 16px;
  list-style: none;
  cursor: pointer;
  text-align: center;
  font-size: 18px;
  font-weight: 600;
  line-height: 1.3;
  color: #000;
  background: var(--ax-switch-bg);
  border: 2px solid var(--ax-switch-border);
  border-radius: 16px;
  transition: background-color 0.14s ease, border-color 0.14s ease, color 0.14s ease;
}

.ax-switch > details > summary::-webkit-details-marker {
  display: none;
}

.ax-switch > details > summary:hover {
  border-color: #e0bc79;
}

.ax-switch > details > summary:focus-visible {
  outline: 2px solid #0059ff;
  outline-offset: 2px;
}

.ax-switch > details[open] > summary {
  color: #fff;
  background: var(--ax-switch-active);
  border-color: var(--ax-switch-active);
}

/* Onglets : sur un navigateur qui sait styler le contenu d'un <details>, les boutons forment une
 * ligne et le volet ouvert occupe toute la largeur dessous. Sinon, les volets s'empilent. */
@supports selector(::details-content) {
  .ax-switch {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px 16px;
  }

  .ax-switch:has(> details:nth-child(3)) {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .ax-switch:has(> details:nth-child(4)) {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .ax-switch > details {
    display: contents;
  }

  .ax-switch > details > summary {
    grid-row: 1;
  }

  .ax-switch > details::details-content {
    grid-column: 1 / -1;
    grid-row: 2;
  }

  .ax-switch > details[open]::details-content {
    box-sizing: border-box;
    padding: 24px;
    background: var(--ax-switch-bg);
    border: 2px solid var(--ax-switch-border);
    border-radius: 16px;
    animation: ax-fade-in 0.3s ease-out;
  }

  @media (prefers-reduced-motion: reduce) {
    .ax-switch > details[open]::details-content {
      animation: none;
    }
  }

  @media (max-width: 575px) {
    .ax-switch > details[open]::details-content {
      padding: 16px;
    }
  }
}

@media (max-width: 575px) {
  .ax-switch > details > summary {
    min-height: 52px;
    padding: 10px 6px;
    font-size: 15px;
  }
}

/* Graphique : le canevas à gauche, la légende (générée à partir des données) à droite. */
.ax-chart {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 24px 40px;
}

.ax-chart .ax-chart__canvas {
  position: relative;
  flex: 0 1 360px;
  width: 100%;
  max-width: 360px;
}

/* Courbes et barres (classe posée par teaser_widgets.js) : toute la largeur, hauteur fixée. */
.ax-chart.ax-chart--wide .ax-chart__canvas {
  flex: 1 1 100%;
  max-width: none;
  height: clamp(260px, 32vw, 380px);
}

.ax-chart .ax-chart__legend {
  flex: 1 1 280px;
  min-width: 0;
  font-size: 14px;
  line-height: 1.4;
  color: #2e3e48;
}

.ax-chart .ax-chart__legend-title {
  margin: 0 0 12px;
  font-weight: 600;
  color: #000;
}

.ax-chart .ax-chart__legend ul {
  display: grid;
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.ax-chart .ax-chart__legend li {
  display: grid;
  grid-template-columns: 14px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: baseline;
  margin: 0;
  padding: 0;
}

.ax-chart .ax-chart__chip {
  display: block;
  width: 14px;
  height: 14px;
  align-self: center;
  border-radius: 3px;
}

.ax-chart .ax-chart__legend strong {
  font-weight: 600;
  color: #000;
  white-space: nowrap;
}
