/* ==========================================================================
   160 — Bar Chart
   Bar chart vertical de dashboard : chaque barre pousse depuis la base
   (hauteur pilotée par anim.js en rAF, décélération + léger overshoot ~5 %
   puis settle), la valeur compte au-dessus en synchro exacte sur la durée
   de la barre. Axe et labels fondent en cascade. La meilleure barre est
   mise en évidence (accent-2 + glow). Déclenchement à l'entrée dans le
   viewport, bouton rejouer discret.
   Racine : .bar-chart (js: true).
   ========================================================================== */

.bar-chart {
  --bc-accent: var(--ml-accent, #7c8cff);
  --bc-accent-2: var(--ml-accent-2, #2dd4bf);
  --bc-muted: var(--ml-muted, #8b91a3);

  position: relative;
  display: flex;
  flex-direction: column;
  gap: 14px;
  width: 100%;
  max-width: 340px;
  color: var(--ml-fg, #e8eaf2);
}

.bar-chart__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.bar-chart__title {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--bc-muted);
}

/* --- Plot ------------------------------------------------------------------ */

.bar-chart__plot {
  position: relative;
  display: flex;
  align-items: stretch;
  gap: 12px;
  height: 180px;
}

/* ligne de base, au-dessus des noms (27px = hauteur du nom + sa marge) */
.bar-chart__plot::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 27px;
  height: 1px;
  background: color-mix(in srgb, var(--bc-muted) 30%, transparent);
  transition: opacity 500ms ease;
}

.bar-chart__col {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  min-width: 0;
}

.bar-chart__value {
  font-size: 11.5px;
  font-weight: 700;
  line-height: 16px;
  font-variant-numeric: tabular-nums;
  margin-bottom: 6px; /* = VALUE_GAP dans anim.js */
  white-space: nowrap;
  transition:
    opacity 320ms ease,
    transform 320ms cubic-bezier(0.2, 0.7, 0.25, 1);
}

.bar-chart__bar {
  width: 100%;
  max-width: 34px;
  height: 0; /* hauteur animée inline par anim.js */
  border-radius: 6px 6px 2px 2px;
  background: linear-gradient(
    180deg,
    color-mix(in srgb, var(--bc-accent) 78%, #ffffff) 0%,
    var(--bc-accent) 42%,
    color-mix(in srgb, var(--bc-accent) 45%, var(--ml-bg, #0d1017)) 100%
  );
  will-change: height;
}

.bar-chart__name {
  height: 14px;
  line-height: 14px;
  margin-top: 13px; /* = NAME_GAP dans anim.js */
  font-size: 10px;
  font-weight: 500;
  color: var(--bc-muted);
  max-width: 100%;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  transition:
    opacity 400ms ease,
    transform 400ms cubic-bezier(0.2, 0.7, 0.25, 1);
}

/* --- Meilleure barre : accent-2 + glow -------------------------------------- */

.bar-chart__col.is-top .bar-chart__bar {
  background: linear-gradient(
    180deg,
    color-mix(in srgb, var(--bc-accent-2) 72%, #ffffff) 0%,
    var(--bc-accent-2) 42%,
    color-mix(in srgb, var(--bc-accent-2) 45%, var(--ml-bg, #0d1017)) 100%
  );
  box-shadow:
    0 0 18px color-mix(in srgb, var(--bc-accent-2) 40%, transparent),
    0 0 3px color-mix(in srgb, var(--bc-accent-2) 55%, transparent);
}

.bar-chart__col.is-top .bar-chart__value {
  color: var(--bc-accent-2);
}

/* --- États : armé (avant lecture) / joué ------------------------------------- */

/* .is-armed est posé par anim.js à l'init (hors reduced-motion) : cache
   valeurs, noms et ligne de base en attendant l'entrée dans le viewport */
.bar-chart.is-armed .bar-chart__value {
  opacity: 0;
  transform: translateY(8px);
}

.bar-chart.is-armed .bar-chart__name {
  opacity: 0;
  transform: translateY(4px);
}

.bar-chart.is-armed .bar-chart__plot::after {
  opacity: 0;
}

/* .is-played (racine) : axe + noms fondent en cascade (délai par colonne) */
.bar-chart.is-played .bar-chart__name {
  opacity: 1;
  transform: none;
  transition-delay: calc(140ms + var(--bc-i, 0) * 60ms);
}

.bar-chart.is-played .bar-chart__plot::after {
  opacity: 1;
  transition-delay: 100ms;
}

/* .is-on (colonne) : la valeur apparaît quand sa barre démarre */
.bar-chart .bar-chart__col.is-on .bar-chart__value {
  opacity: 1;
  transform: none;
}

/* --- Bouton rejouer ----------------------------------------------------------- */

.bar-chart__replay {
  appearance: none;
  border: 1px solid color-mix(in srgb, var(--bc-muted) 35%, transparent);
  background: transparent;
  color: var(--bc-muted);
  width: 26px;
  height: 26px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition:
    color 200ms ease,
    border-color 200ms ease,
    transform 200ms cubic-bezier(0.3, 1.4, 0.5, 1);
}

.bar-chart__replay:hover {
  color: var(--ml-fg, #e8eaf2);
  border-color: color-mix(in srgb, var(--bc-muted) 60%, transparent);
}

.bar-chart__replay:hover .bar-chart__replay-icon {
  transform: rotate(-45deg);
}

.bar-chart__replay:active {
  transform: scale(0.92);
}

.bar-chart__replay:focus-visible {
  outline: 2px solid var(--bc-accent);
  outline-offset: 2px;
}

.bar-chart__replay-icon {
  width: 13px;
  height: 13px;
  display: block;
  transition: transform 300ms cubic-bezier(0.2, 0.7, 0.25, 1);
}

/* --- Reduced motion ------------------------------------------------------------ */

@media (prefers-reduced-motion: reduce) {
  .bar-chart__value,
  .bar-chart__name,
  .bar-chart__plot::after,
  .bar-chart__replay,
  .bar-chart__replay-icon {
    transition: none;
  }
}
