/* ==============================================================================
   LOADING-STATES.CSS — États de chargement TikeWA
   ==============================================================================
   Composants réutilisables d'attente perçue : barre de progression de navigation,
   overlay bloquant, spinner, skeletons, carte d'erreur + bouton « Réessayer ».

   Règle : ce fichier CONSOMME uniquement les tokens de Css/tokens.css
   (--accent, --primary, --ink, --muted, --line, --radius-*, --shadow-*, --space-*, --transition).
   Aucune couleur de marque ni rayon n'est redéfini ici.

   Pilotage JS : js/loading-states.js (window.TikeLoading).
   ============================================================================== */

/* ------------------------------------------------------------------------------
   1. BARRE DE PROGRESSION FINE (haut de page, navigation)
   ------------------------------------------------------------------------------ */
.tk-progressbar {
    position: fixed;
    top: 0;
    left: 0;
    height: 3px;
    width: 0;
    background: var(--accent, #FF4A0D);
    box-shadow: 0 0 8px var(--accent-glow, rgba(255, 74, 13, 0.25));
    z-index: 99999;
    opacity: 0;
    pointer-events: none;
    transition: width 0.2s ease, opacity 0.25s ease;
}

.tk-progressbar.tk-active {
    opacity: 1;
}

/* ------------------------------------------------------------------------------
   2. OVERLAY BLOQUANT (paiement / action longue)
   ------------------------------------------------------------------------------ */
.tk-overlay {
    position: fixed;
    inset: 0;
    z-index: 99998;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-4, 24px);
    background: rgba(0, 0, 0, 0.55);
    -webkit-backdrop-filter: blur(3px);
    backdrop-filter: blur(3px);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s ease, visibility 0.2s ease;
}

.tk-overlay.tk-active {
    opacity: 1;
    visibility: visible;
}

.tk-overlay-card {
    background: var(--paper, #ffffff);
    border-radius: var(--radius-lg, 14px);
    box-shadow: var(--shadow-xl, 0 20px 30px -5px rgba(16, 24, 40, 0.10));
    padding: var(--space-6, 48px) var(--space-5, 32px);
    max-width: 420px;
    width: 100%;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-3, 16px);
}

.tk-overlay-card.tk-overlay-card--error {
    border-top: 4px solid var(--danger, #ef4444);
}

.tk-overlay-icon {
    width: 56px;
    height: 56px;
    border-radius: var(--radius-full, 9999px);
    display: grid;
    place-items: center;
    background: var(--accent-soft, #FFF2ED);
    color: var(--accent, #FF4A0D);
    font-size: 1.6rem;
}

.tk-overlay-card--error .tk-overlay-icon {
    background: var(--danger-soft, #fef2f2);
    color: var(--danger, #ef4444);
}

.tk-overlay-title {
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--ink, #000000);
    margin: 0;
}

.tk-overlay-text {
    font-size: 0.9rem;
    line-height: 1.5;
    color: var(--muted, #737373);
    margin: 0;
}

/* ------------------------------------------------------------------------------
   3. SPINNER (boutons + overlay)
   ------------------------------------------------------------------------------ */
.tk-spinner {
    display: inline-block;
    width: 1em;
    height: 1em;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: var(--radius-full, 9999px);
    animation: tk-spin 0.7s linear infinite;
    vertical-align: -0.125em;
    margin-right: 6px;
}

.tk-spinner--lg {
    width: 40px;
    height: 40px;
    border-width: 3px;
    margin: 0;
    color: var(--accent, #FF4A0D);
}

@keyframes tk-spin {
    to {
        transform: rotate(360deg);
    }
}

/* Bouton en attente : neutralise la règle disabled globale (opacity .72) pour rester lisible */
.btn.tk-busy,
button.tk-busy {
    opacity: 1 !important;
    cursor: progress !important;
}

/* ------------------------------------------------------------------------------
   4. SKELETON SCREENS (listes, cartes, tableaux chargés dynamiquement)
   ------------------------------------------------------------------------------ */
.tk-skeleton {
    position: relative;
    overflow: hidden;
    background: var(--line-light, #F5F5F5);
    border-radius: var(--radius-sm, 8px);
    color: transparent !important;
}

.tk-skeleton::after {
    content: "";
    position: absolute;
    inset: 0;
    transform: translateX(-100%);
    background: linear-gradient(90deg,
            transparent,
            rgba(255, 255, 255, 0.8),
            transparent);
    animation: tk-shimmer 1.4s infinite;
}

.tk-skeleton-text {
    height: 12px;
    margin-bottom: var(--space-2, 8px);
    width: 100%;
}

.tk-skeleton-text.tk-w-60 { width: 60%; }
.tk-skeleton-text.tk-w-40 { width: 40%; }

.tk-skeleton-card {
    height: 220px;
    border-radius: var(--radius-lg, 14px);
}

.tk-skeleton-line {
    height: 40px;
    margin-bottom: var(--space-2, 8px);
}

@keyframes tk-shimmer {
    100% {
        transform: translateX(100%);
    }
}

/* ------------------------------------------------------------------------------
   5. CARTE D'ERREUR + BOUTON « RÉESSAYER »
   ------------------------------------------------------------------------------ */
.tk-error-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-3, 16px);
    padding: var(--space-6, 48px) var(--space-4, 24px);
    background: var(--paper, #ffffff);
    border: 1px solid var(--line, #e5e5e5);
    border-left: 4px solid var(--danger, #ef4444);
    border-radius: var(--radius-md, 10px);
    text-align: center;
}

.tk-error-icon {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-full, 9999px);
    display: grid;
    place-items: center;
    background: var(--danger-soft, #fef2f2);
    color: var(--danger, #ef4444);
    font-size: 1.4rem;
}

.tk-error-title {
    font-size: 1rem;
    font-weight: 700;
    color: var(--ink, #000000);
    margin: 0;
}

.tk-error-text {
    font-size: 0.88rem;
    color: var(--muted, #737373);
    margin: 0;
    max-width: 42ch;
}

.tk-retry-btn {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2, 8px);
    padding: 10px var(--space-4, 24px);
    border: none;
    border-radius: var(--radius-sm, 8px);
    background: var(--accent, #FF4A0D);
    color: var(--paper, #ffffff);
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: 700;
    cursor: pointer;
    transition: var(--transition, all 0.2s cubic-bezier(0.4, 0, 0.2, 1));
}

.tk-retry-btn:hover {
    background: var(--accent-dark, #E03E08);
}

/* ------------------------------------------------------------------------------
   6. RESPECT DE prefers-reduced-motion (accessibilité)
   ------------------------------------------------------------------------------ */
@media (prefers-reduced-motion: reduce) {

    .tk-spinner,
    .tk-skeleton::after {
        animation-duration: 2.4s;
    }

    .tk-progressbar,
    .tk-overlay {
        transition-duration: 0.01ms;
    }
}
