/*
 * PRESTKA V15 — Toasts globaux (LOT 0.2, SUPER PROMPT DG 2026-07-20).
 *
 * Pile de notifications en haut à droite, empilées, auto-effacées à 5 s.
 * Lié automatiquement par Propshaft (`stylesheet_link_tag :app`) — surtout PAS
 * d'@import, qui produirait un 404 sur chemin non digesté (audit 2026-07-06).
 *
 * Bi-thème : les teintes viennent de --toast-* (tokens.css, définis dans les DEUX
 * blocs :root et [data-theme="light"]). Aucune couleur en dur ici.
 */

.toasts {
  position: fixed;
  /* Sous la topbar : sinon la pile recouvre la cloche de notifications et l'avatar
     du menu profil pendant 5 s, les rendant incliquables. */
  top: calc(var(--topbar-h) + var(--space-3));
  right: var(--space-5);
  z-index: var(--z-toast);          /* 1100 — au-dessus des modales (1000) */
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  width: min(380px, calc(100vw - var(--space-5) * 2));
  pointer-events: none;             /* la pile ne doit pas bloquer les clics */
}

/* Chaque toast, lui, reste cliquable (bouton fermer, pause au survol). */
.toast {
  pointer-events: auto;
  position: relative;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: start;
  gap: var(--space-3);
  padding: var(--space-4);
  border-radius: var(--radius-lg);
  overflow: hidden;
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  line-height: var(--leading-snug);
  /* Liseré coloré à gauche = signal de variante, lisible dans les 2 thèmes. */
  border-left: 3px solid var(--toast-accent, var(--toast-info));
}

.toast--success { --toast-accent: var(--toast-success); }
.toast--error   { --toast-accent: var(--toast-error); }
.toast--info    { --toast-accent: var(--toast-info); }

.toast__icon {
  width: 20px;
  height: 20px;
  flex: none;
  color: var(--toast-accent, var(--toast-info));
}

.toast__message {
  margin: 0;
  color: var(--text-primary);
  overflow-wrap: anywhere;          /* un message long ne doit pas déborder */
}

.toast__close {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  padding: 0;
  border: 0;
  border-radius: var(--radius-sm);
  /* Leçon Lot A : tout <button> local doit poser un background explicite. */
  background: transparent;
  color: var(--text-tertiary);
  cursor: pointer;
  transition: color var(--dur-fast) var(--ease-silk),
              background var(--dur-fast) var(--ease-silk);
}
.toast__close:hover { color: var(--text-primary); background: var(--bg-elevated); }
.toast__close:focus-visible { outline: var(--focus-ring); outline-offset: 2px; }
.toast__close .icon { width: 14px; height: 14px; }

/* Barre de progression du compte à rebours — retour visuel du délai restant. */
.toast__timer {
  position: absolute;
  left: 0;
  bottom: 0;
  height: 2px;
  width: 100%;
  transform-origin: left center;
  background: var(--toast-accent, var(--toast-info));
  opacity: 0.55;
  animation: toast-timer var(--toast-remaining, 5000ms) linear forwards;
}
.toast--paused .toast__timer { animation-play-state: paused; }

@keyframes toast-timer {
  from { transform: scaleX(1); }
  to   { transform: scaleX(0); }
}

/* ===== Entrée / sortie ===== */
.toast--in  { animation: toast-in  var(--dur-normal) var(--ease-spring) both; }
.toast--out { animation: toast-out var(--dur-fast)   var(--ease-silk)  both; }

@keyframes toast-in {
  from { opacity: 0; transform: translateX(16px) scale(0.98); }
  to   { opacity: 1; transform: translateX(0)    scale(1); }
}
@keyframes toast-out {
  from { opacity: 1; transform: translateX(0)    scale(1); }
  to   { opacity: 0; transform: translateX(16px) scale(0.98); }
}

/* ===== Mobile : pleine largeur en haut, sous la topbar ===== */
@media (max-width: 640px) {
  .toasts {
    top: calc(var(--topbar-h) + var(--space-2));
    right: var(--space-3);
    left: var(--space-3);
    width: auto;
  }
}

/* ===== Accessibilité : respect de prefers-reduced-motion ===== */
@media (prefers-reduced-motion: reduce) {
  .toast--in,
  .toast--out,
  .toast__timer {
    animation: none;
  }
  /* Sans animation, la barre resterait pleine : on la masque plutôt que de mentir. */
  .toast__timer { display: none; }
}

/* ===== Fallback verre : sans backdrop-filter, il faut un fond opaque ===== */
@supports not (backdrop-filter: blur(1px)) {
  .toast { background: var(--surface-solid); }
}
