/* Retours à l'utilisateur : toasts, barre de progression, indicateurs, messages, états, confirmations.
   Composants centralisés (macros dans templates/_ui.html, comportement dans static/js/feedback.js).
   Uniquement des rôles --as-* (socle:FRO-02) : aucune couleur en dur. */

/* ---------- Indicateur de chargement ---------- */
.spinner { display: inline-block; flex: none; width: 18px; height: 18px; border-radius: 50%;
  border: 2px solid color-mix(in srgb, currentColor 25%, transparent); border-top-color: currentColor;
  animation: as-spin .7s linear infinite; vertical-align: -3px; }
.spinner-sm { width: 14px; height: 14px; border-width: 2px; vertical-align: -2px; }
.spinner-lg { width: 32px; height: 32px; border-width: 3px; color: var(--as-color-primary); }
@keyframes as-spin { to { transform: rotate(360deg); } }

/* Bouton pendant l'envoi : même taille, curseur d'attente, plus de double clic. */
button.is-loading, .btn.is-loading { cursor: progress; pointer-events: none; opacity: .85; }

/* Barre de progression fine en haut de l'écran (navigation, requêtes HTMX, envois). */
.progress { position: fixed; inset: 0 0 auto 0; z-index: 200; height: 3px; pointer-events: none; opacity: 0; transition: opacity var(--as-duration-base) var(--as-easing); }
.progress.active { opacity: 1; }
.progress > span { display: block; height: 100%; width: 0; background: var(--as-color-accent);
  box-shadow: 0 0 8px color-mix(in srgb, var(--as-color-accent) 60%, transparent);
  transition: width .25s var(--as-easing); }

/* Zone qui se recharge (HTMX) : contenu atténué et indicateur centré, sans saut de mise en page. */
[aria-busy="true"][data-loading-region], .htmx-request[data-loading-region] { position: relative; }
[aria-busy="true"][data-loading-region] > *, .htmx-request[data-loading-region] > * { opacity: .45; transition: opacity var(--as-duration-fast); }
[aria-busy="true"][data-loading-region]::after, .htmx-request[data-loading-region]::after {
  content: ""; position: absolute; top: 72px; left: calc(50% - 14px); width: 28px; height: 28px; border-radius: 50%;
  border: 3px solid color-mix(in srgb, var(--as-color-primary) 22%, transparent); border-top-color: var(--as-color-primary);
  animation: as-spin .7s linear infinite; }

/* Squelettes */
.skeleton { display: flex; flex-direction: column; gap: var(--as-space-3); padding: var(--as-space-4) var(--as-space-5); }
.sk-row { display: flex; gap: var(--as-space-3); align-items: center; }
.sk { display: block; height: 12px; border-radius: var(--as-radius-sm);
  background: linear-gradient(90deg, var(--as-color-surface-muted) 0%, var(--as-color-border) 50%, var(--as-color-surface-muted) 100%);
  background-size: 200% 100%; animation: as-shimmer 1.4s ease-in-out infinite; }
.sk-a { width: 72px; } .sk-b { flex: 1; max-width: 420px; }
.sk-row:nth-child(2n) .sk-b { max-width: 300px; } .sk-row:nth-child(3n) .sk-b { max-width: 360px; }
@keyframes as-shimmer { from { background-position: 100% 0; } to { background-position: -100% 0; } }

/* ---------- Toasts : discrets, en bas à droite, refermés seuls (sauf erreurs) ---------- */
.toast-region { position: fixed; inset-inline-end: var(--as-space-5); bottom: var(--as-space-5); z-index: 150;
  display: flex; flex-direction: column; align-items: flex-end; gap: var(--as-space-2); width: min(400px, calc(100vw - 24px)); pointer-events: none; }
body:has(.form-bar) .toast-region { bottom: 88px; }
.toast { position: relative; display: flex; align-items: flex-start; gap: var(--as-space-3); width: 100%; overflow: hidden;
  padding: var(--as-space-3) var(--as-space-3) var(--as-space-3) var(--as-space-4); pointer-events: auto;
  background: var(--as-color-surface); color: var(--as-color-text); border: 1px solid var(--as-color-border);
  border-radius: var(--as-radius-lg); box-shadow: var(--as-shadow-lg); animation: as-toast-in var(--as-duration-base) var(--as-easing); }
.toast.leaving { animation: as-toast-out .18s var(--as-easing) forwards; }
.toast-icon { width: 20px; height: 20px; margin-top: 1px; flex: none; fill: none; stroke-width: 2; }
.toast-success .toast-icon { color: var(--as-status-success); }
.toast-info .toast-icon { color: var(--as-status-info); }
.toast-warning .toast-icon { color: var(--as-color-accent-text); }
.toast-error .toast-icon { color: var(--as-status-danger); }
.toast-error { border-color: color-mix(in srgb, var(--as-status-danger) 45%, var(--as-color-border)); }
.toast-body { flex: 1; min-width: 0; }
.toast-title { margin: 0 0 2px; font-weight: var(--as-font-weight-semibold); font-size: var(--as-font-size-sm); }
.toast-text { margin: 0; font-size: var(--as-font-size-sm); color: var(--as-color-text-muted); overflow-wrap: anywhere; }
.toast-title + .toast-text { color: var(--as-color-text-muted); }
.toast:not(:has(.toast-title)) .toast-text { color: var(--as-color-text); }
.toast-action { display: inline-block; margin-top: var(--as-space-1); font-size: var(--as-font-size-sm); font-weight: var(--as-font-weight-semibold); }
.toast-close { flex: none; display: inline-flex; align-items: center; justify-content: center; width: 28px; height: 28px; min-height: 0; margin: -2px -2px 0 0; padding: 0;
  border: 0; border-radius: var(--as-radius-md); background: transparent; color: var(--as-color-text-muted); cursor: pointer; }
.toast-close:hover { background: var(--as-color-surface-muted); color: var(--as-color-text); border-color: transparent; }
.toast-close .icon { width: 16px; height: 16px; }
.toast-timer { position: absolute; inset: auto 0 0 0; height: 2px; transform-origin: left; background: currentColor; opacity: .25;
  animation: as-timer linear forwards; }
.toast-success .toast-timer { color: var(--as-status-success); } .toast-info .toast-timer { color: var(--as-status-info); }
.toast-warning .toast-timer { color: var(--as-color-accent); }
.toast.paused .toast-timer { animation-play-state: paused; }
@keyframes as-timer { from { transform: scaleX(1); } to { transform: scaleX(0); } }
@keyframes as-toast-in { from { opacity: 0; transform: translateY(8px) scale(.98); } to { opacity: 1; transform: none; } }
@keyframes as-toast-out { to { opacity: 0; transform: translateX(16px); } }
/* Sans script, les toasts du serveur restent simplement affichés en haut du contenu. */
.toast-region:not(:has(.toast-close)) .toast { animation: none; }

/* ---------- Messages d'information dans la page ---------- */
.alert { display: flex; gap: var(--as-space-3); align-items: flex-start; margin: 0 0 var(--as-space-4);
  padding: var(--as-space-3) var(--as-space-4); border-radius: var(--as-radius-lg); border: 1px solid; font-size: var(--as-font-size-sm); }
.alert-icon { width: 20px; height: 20px; flex: none; margin-top: 1px; fill: none; stroke-width: 2; }
.alert-body { flex: 1; min-width: 0; }
.alert-title { margin: 0; font-weight: var(--as-font-weight-semibold); font-size: var(--as-font-size-md); }
.alert-text { color: var(--as-color-text); }
.alert-title + .alert-text { margin-top: 2px; }
.alert-text p { margin: 0; } .alert-text p + p { margin-top: var(--as-space-1); }
.alert ul { margin: var(--as-space-1) 0 0; padding-inline-start: var(--as-space-5); }
.alert-close { width: 28px; height: 28px; margin: -4px -6px 0 0; }
.alert-info { background: var(--as-status-info-bg); border-color: color-mix(in srgb, var(--as-status-info) 30%, transparent); }
.alert-info .alert-icon, .alert-info .alert-title { color: var(--as-status-info); }
.alert-success { background: var(--as-status-success-bg); border-color: color-mix(in srgb, var(--as-status-success) 30%, transparent); }
.alert-success .alert-icon, .alert-success .alert-title { color: var(--as-status-success); }
.alert-warning { background: var(--as-status-warning-bg); border-color: color-mix(in srgb, var(--as-color-accent) 45%, transparent); }
.alert-warning .alert-icon, .alert-warning .alert-title { color: var(--as-status-warning); }
.alert-error { background: var(--as-status-danger-bg); border-color: color-mix(in srgb, var(--as-status-danger) 35%, transparent); }
.alert-error .alert-icon, .alert-error .alert-title { color: var(--as-status-danger); }
.alert a { font-weight: var(--as-font-weight-semibold); }

/* Aide contextuelle « ? » (popover natif) */
.help-btn { display: inline-flex; align-items: center; justify-content: center; width: 22px; height: 22px; min-height: 0; margin: 0 0 0 4px; padding: 0;
  vertical-align: -5px; border: 0; border-radius: 50%; background: transparent; color: var(--as-color-text-muted); cursor: help; anchor-name: --help; }
.help-btn:hover { background: var(--as-color-surface-muted); color: var(--as-color-primary); border-color: transparent; }
.help-btn .icon { width: 16px; height: 16px; }
.help-pop { max-width: 320px; margin: 0; padding: var(--as-space-3) var(--as-space-4); border: 1px solid var(--as-color-border); border-radius: var(--as-radius-lg);
  background: var(--as-color-surface); color: var(--as-color-text); box-shadow: var(--as-shadow-lg); font-size: var(--as-font-size-sm); font-weight: var(--as-font-weight-regular); line-height: 1.5; }
.help-pop::backdrop { background: transparent; }

/* ---------- États d'une zone : vide, aucun résultat, erreur, accès refusé, chargement ---------- */
.state { display: flex; flex-direction: column; align-items: center; gap: var(--as-space-2); padding: var(--as-space-12) var(--as-space-6); text-align: center; }
.state-art svg { width: 72px; height: 72px; fill: none; }
.art-bg { fill: var(--as-color-surface-muted); }
.art-line { stroke: var(--as-color-text-muted); stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; fill: none; }
.art-accent-line { stroke: var(--as-color-accent); stroke-width: 2.5; stroke-linecap: round; fill: none; }
.art-accent { fill: var(--as-color-accent); }
.state-error .art-line { stroke: var(--as-status-danger); }
.state-done .art-line { stroke: var(--as-status-success); }
.state-title { margin: var(--as-space-2) 0 0; font-size: var(--as-font-size-base); font-weight: var(--as-font-weight-semibold); }
.state-text { margin: 0; max-width: 52ch; color: var(--as-color-text-muted); }
.state-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: var(--as-space-2); margin-top: var(--as-space-3); }
.state-actions .btn { margin: 0; }
.state-loading .state-title { color: var(--as-color-text-muted); font-weight: var(--as-font-weight-medium); }

/* ---------- Validation des formulaires ---------- */
.field-error { display: flex; gap: 6px; align-items: center; margin: var(--as-space-1) 0 0; color: var(--as-status-danger); font-size: var(--as-font-size-sm); font-weight: var(--as-font-weight-medium); }
.field-error::before { content: ""; flex: none; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
[aria-invalid="true"] { border-color: var(--as-status-danger) !important; box-shadow: 0 0 0 1px var(--as-status-danger); }
.form-errors { margin-bottom: var(--as-space-4); }

/* ---------- Fenêtre de confirmation ---------- */
dialog.confirm { width: min(480px, calc(100vw - 32px)); }
.confirm-main { display: flex; gap: var(--as-space-4); padding: var(--as-space-5) var(--as-space-5) var(--as-space-2); }
.confirm-main h2 { margin: 2px 0 var(--as-space-2); font-size: var(--as-font-size-lg); }
.confirm-main p { margin: 0; color: var(--as-color-text-muted); }
.confirm-icon { display: inline-flex; align-items: center; justify-content: center; flex: none; width: 40px; height: 40px; border-radius: 50%;
  background: var(--as-color-primary-soft); color: var(--as-color-primary); }
.confirm-icon .icon { width: 22px; height: 22px; }
.confirm-danger .confirm-icon { background: var(--as-status-danger-bg); color: var(--as-status-danger); }
.confirm-require { margin-top: var(--as-space-3); }
.confirm-require label { font-weight: var(--as-font-weight-regular); }
dialog.modal[open] { animation: as-pop var(--as-duration-base) var(--as-easing); }
dialog.modal::backdrop { backdrop-filter: blur(2px); }
@keyframes as-pop { from { opacity: 0; transform: translateY(6px) scale(.98); } to { opacity: 1; transform: none; } }
.shortcuts { display: grid; gap: var(--as-space-2); margin: 0; }
.shortcuts > div { display: flex; justify-content: space-between; gap: var(--as-space-4); padding: var(--as-space-2) 0; border-bottom: 1px solid var(--as-color-border); }
.shortcuts > div:last-child { border-bottom: 0; }
.shortcuts dt { white-space: nowrap; } .shortcuts dd { margin: 0; color: var(--as-color-text-muted); text-align: end; }

/* Copier */
.copy-btn { width: 32px; height: 32px; color: var(--as-color-text-muted); }
.copy-btn.copied { color: var(--as-status-success); }

@media (max-width: 599px) {
  .toast-region { inset-inline: 12px; bottom: 12px; width: auto; }
  body:has(.form-bar) .toast-region { bottom: 84px; }
}
@media (prefers-reduced-motion: reduce) {
  .spinner, .sk, [aria-busy="true"][data-loading-region]::after, .htmx-request[data-loading-region]::after { animation-duration: 2s; }
  .toast, .toast.leaving, dialog.modal[open] { animation: none; }
  .progress > span { transition: none; }
}

/* Transitions discrètes entre les pages (navigateurs récents ; ignorées ailleurs et si l'animation est réduite). */
@view-transition { navigation: auto; }
::view-transition-old(root), ::view-transition-new(root) { animation-duration: 140ms; }
@media (prefers-reduced-motion: reduce) { @view-transition { navigation: none; } }
