/* Lazy loading — rendu différé visible (squelettes + cascade) */

:root {
    --lazy-shimmer-base: #e8f0eb;
    --lazy-shimmer-highlight: #f7fdf9;
    --lazy-shimmer-accent: oklch(0.82 0.06 155);
}

html[data-theme="dark"] {
    --lazy-shimmer-base: #2a3430;
    --lazy-shimmer-highlight: #354038;
    --lazy-shimmer-accent: oklch(0.45 0.06 155);
}

/* Barre de progression globale */
.lazy-progress {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    z-index: 10050;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.lazy-progress.is-active {
    opacity: 1;
}

.lazy-progress-bar {
    display: block;
    height: 100%;
    width: 0;
    background: linear-gradient(90deg, var(--accent, #f19a3e) 0%, oklch(0.62 0.14 155) 55%, var(--accent, #f19a3e) 100%);
    background-size: 200% 100%;
    box-shadow: 0 0 12px oklch(0.72 0.12 55 / 0.45);
    transition: width 0.35s ease;
}

.lazy-progress.is-active .lazy-progress-bar {
    animation: lazy-progress-pulse 1.1s ease-in-out infinite;
}

@keyframes lazy-progress-pulse {
    0% { width: 8%; margin-left: 0; }
    50% { width: 42%; margin-left: 38%; }
    100% { width: 8%; margin-left: 92%; }
}

.lazy-progress.is-done .lazy-progress-bar {
    animation: none;
    width: 100%;
    margin-left: 0;
    transition: width 0.25s ease;
}

/* Overlay navigation */
body.is-page-loading::before {
    content: "";
    position: fixed;
    inset: 0;
    z-index: 10040;
    background: oklch(0.98 0.02 155 / 0.62);
    backdrop-filter: blur(3px);
    pointer-events: none;
    animation: lazy-overlay-in 0.25s ease;
}

body.is-page-loading::after {
    content: "";
    position: fixed;
    top: 50%;
    left: 50%;
    z-index: 10041;
    width: 2.5rem;
    height: 2.5rem;
    margin: -1.25rem 0 0 -1.25rem;
    border: 3px solid oklch(0.88 0.03 155);
    border-top-color: var(--accent, #f19a3e);
    border-radius: 50%;
    animation: lazy-spin 0.75s linear infinite;
    pointer-events: none;
}

@keyframes lazy-overlay-in {
    from { opacity: 0; }
    to { opacity: 1; }
}

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

/* Sections lourdes — paint différé */
.lazy-section:not(.is-lazy-section-ready) {
    content-visibility: auto;
    contain-intrinsic-size: auto 360px;
}

/* ── Squelette shimmer ── */
[data-lazy-reveal].is-lazy-pending,
.lazy-section.is-lazy-pending {
    position: relative;
}

/* Ne jamais masquer le contenu — shimmer léger uniquement */
[data-lazy-reveal].is-lazy-pending::before,
.lazy-section.is-lazy-pending::before {
    content: "";
    position: absolute;
    inset: 0;
    z-index: 1;
    border-radius: inherit;
    pointer-events: none;
    opacity: 0.55;
    background: linear-gradient(
        105deg,
        transparent 0%,
        oklch(0.98 0.02 155 / 0.65) 50%,
        transparent 100%
    );
    background-size: 220% 100%;
    animation: lazy-shimmer 1.35s ease-in-out infinite;
}

[data-lazy-reveal].is-lazy-pending::after,
.lazy-section.is-lazy-pending::after {
    display: none;
}

/* Lignes squelette selon le type de bloc */
.matrice-partner-card.is-lazy-pending {
    min-height: 9.5rem;
}

.matrice-partner-card.is-lazy-pending::after {
    top: 3.25rem;
    left: 0.875rem;
    right: 0.875rem;
    height: 0.625rem;
    box-shadow:
        0 1.125rem 0 0 oklch(0.9 0.02 155 / 0.45),
        0 2.25rem 0 0 oklch(0.9 0.02 155 / 0.35),
        0 3.375rem 0 0 oklch(0.9 0.02 155 / 0.25);
}

.matrice-excel-group.is-lazy-pending {
    display: table-row-group;
}

tr.matrice-excel-row.is-lazy-pending > td {
    opacity: 0;
    visibility: hidden;
    background: var(--lazy-shimmer-base);
}

tr.matrice-excel-row.is-lazy-pending > td:first-child {
    background: linear-gradient(
        105deg,
        var(--lazy-shimmer-base) 0%,
        var(--lazy-shimmer-highlight) 50%,
        var(--lazy-shimmer-base) 100%
    );
    background-size: 220% 100%;
    animation: lazy-shimmer 1.35s ease-in-out infinite;
}

.notification-item.is-lazy-pending,
.notif-panel-item.is-lazy-pending {
    min-height: 5.5rem;
}

.notification-item.is-lazy-pending::after,
.notif-panel-item.is-lazy-pending::after {
    top: 1rem;
    left: 1rem;
    right: 1rem;
    height: 0.5rem;
    box-shadow: 0 0.875rem 0 0 oklch(0.9 0.02 155 / 0.4);
}

.cabinet-kpi-card.is-lazy-pending,
.cabinet-widget.is-lazy-pending {
    min-height: 7rem;
}

.cabinet-activity-item.is-lazy-pending,
.cabinet-meeting-pill.is-lazy-pending {
    min-height: 4.25rem;
}

.cabinet-activity-item.is-lazy-pending::after,
.cabinet-meeting-pill.is-lazy-pending::after {
    top: 0.875rem;
    left: 3.25rem;
    right: 1rem;
    height: 0.5rem;
    box-shadow: 0 0.875rem 0 0 oklch(0.9 0.02 155 / 0.35);
}

.ministre-kcard.is-lazy-pending,
.diligence-card.is-lazy-pending {
    min-height: 6.5rem;
}

.matrice-diligence-row.is-lazy-pending {
    min-height: 4rem;
}

@keyframes lazy-shimmer {
    0% { background-position: 120% 0; }
    100% { background-position: -120% 0; }
}

/* ── Révélation en cascade ── */
[data-lazy-reveal].is-lazy-revealing > *,
.lazy-section.is-lazy-revealing > * {
    visibility: visible;
}

[data-lazy-reveal].is-lazy-visible,
.lazy-section.is-lazy-section-ready {
    pointer-events: auto;
}

[data-lazy-reveal].is-lazy-visible > *:not(td),
.lazy-section.is-lazy-section-ready > * {
    opacity: 1;
    visibility: visible;
    animation: lazy-content-in 0.55s cubic-bezier(0.22, 1, 0.36, 1) both;
    animation-delay: calc(var(--lazy-stagger, 0ms) + 40ms);
}

tr[data-lazy-reveal].is-lazy-visible > td {
    opacity: 1;
    visibility: visible;
    animation: lazy-content-in 0.55s cubic-bezier(0.22, 1, 0.36, 1) both;
    animation-delay: calc(var(--lazy-stagger, 0ms) + 40ms);
}

[data-lazy-reveal].is-lazy-visible::before,
[data-lazy-reveal].is-lazy-visible::after,
.lazy-section.is-lazy-section-ready::before,
.lazy-section.is-lazy-section-ready::after {
    opacity: 0;
    transition: opacity 0.28s ease;
    pointer-events: none;
}

@keyframes lazy-content-in {
    from {
        opacity: 0;
        transform: translateY(14px) scale(0.985);
        filter: blur(3px);
    }
    to {
        opacity: 1;
        transform: none;
        filter: none;
    }
}

/* Images */
img.lazy-img-pending {
    opacity: 0;
    background: var(--lazy-shimmer-base, #e8f0eb);
    min-height: 2rem;
    animation: lazy-shimmer 1.35s ease-in-out infinite;
    background-size: 220% 100%;
}

img.is-lazy-loaded {
    animation: lazy-img-in 0.5s cubic-bezier(0.22, 1, 0.36, 1) both;
}

@keyframes lazy-img-in {
    from {
        opacity: 0;
        transform: scale(1.03);
        filter: blur(6px);
    }
    to {
        opacity: 1;
        transform: none;
        filter: none;
    }
}

body.is-page-loading .dash-page-content,
body.is-page-loading .lazy-section {
    opacity: 0.35;
    filter: blur(1px);
    transition: opacity 0.2s ease, filter 0.2s ease;
}

@media (prefers-reduced-motion: reduce) {
    [data-lazy-reveal].is-lazy-pending > *,
    .lazy-section.is-lazy-pending > * {
        opacity: 1;
        visibility: visible;
    }

    [data-lazy-reveal].is-lazy-pending::before,
    [data-lazy-reveal].is-lazy-pending::after,
    .lazy-section.is-lazy-pending::before,
    .lazy-section.is-lazy-pending::after,
    .lazy-progress.is-active .lazy-progress-bar,
    body.is-page-loading::after {
        animation: none;
        display: none;
    }

    [data-lazy-reveal].is-lazy-visible > *,
    .lazy-section.is-lazy-section-ready > * {
        animation: none;
    }

    body.is-page-loading::before {
        backdrop-filter: none;
    }
}
