/* ============================================
   PAGE LOADER — branded boot screen
   Bounce adapted from Uiverse.io (mobinkakei), re-themed to the Enne
   palette: jade balls on the app background, logo mark above.

   Two modes, chosen by the inline controller in base.html:
   - cold landing: balls visible immediately, minimum ~0.9s display
   - .loader-quiet (internal nav): opaque background only — reads as a
     quick cross-fade; the bounce fades in only if the load is slow
   ============================================ */

#page-loader {
    position: fixed;
    inset: 0;
    z-index: 10000; /* above --z-toast while booting; removed from flow once hidden */
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--background);
    visibility: visible;
    opacity: 1;
    /* fade-IN speed (EnneLoader.show before an outbound nav) */
    transition: opacity 0.18s ease;
}

/* fade-OUT is slower than fade-in — the reveal should feel unhurried */
#page-loader.loader-done {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.38s ease, visibility 0s 0.38s;
}

#page-loader.loader-instant {
    transition: none;
}

.loader-inner {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 28px;
}

/* Quiet mode: keep the overlay (it is the cross-fade) but only surface the
   bounce when the next page is genuinely slow. */
#page-loader.loader-quiet .loader-inner {
    opacity: 0;
    animation: loaderReveal 0.3s ease 0.35s forwards;
}

@keyframes loaderReveal {
    to { opacity: 1; }
}

.loader-mark {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    display: block;
}

.loader-stage {
    width: 168px;
    height: 58px;
    position: relative;
}

.loader-ball {
    width: 17px;
    height: 17px;
    position: absolute;
    border-radius: 50%;
    background-color: var(--primary);
    left: 12%;
    transform-origin: 50%;
    animation: enneBounce 0.5s alternate infinite ease;
}

.loader-ball:nth-child(2) {
    left: 45%;
    animation-delay: 0.2s;
}

.loader-ball:nth-child(3) {
    left: auto;
    right: 12%;
    animation-delay: 0.3s;
}

@keyframes enneBounce {
    0% {
        top: 44px;
        height: 5px;
        border-radius: 50px 50px 25px 25px;
        transform: scaleX(1.7);
    }
    40% {
        height: 17px;
        border-radius: 50%;
        transform: scaleX(1);
    }
    100% {
        top: 0%;
    }
}

/* Shadows are stage children 4-6; child 4 keeps the base left/delay and
   pairs with ball 1, matching the original composition. */
.loader-shadow {
    width: 17px;
    height: 4px;
    border-radius: 50%;
    background-color: rgba(28, 27, 24, 0.22);
    position: absolute;
    top: 48px;
    transform-origin: 50%;
    left: 12%;
    filter: blur(1px);
    animation: enneShadowPulse 0.5s alternate infinite ease;
}

.loader-shadow:nth-child(5) {
    left: 45%;
    animation-delay: 0.2s;
}

.loader-shadow:nth-child(6) {
    left: auto;
    right: 12%;
    animation-delay: 0.3s;
}

[data-theme="dark"] .loader-shadow {
    background-color: rgba(0, 0, 0, 0.55);
}

@keyframes enneShadowPulse {
    0% { transform: scaleX(1.5); }
    40% { transform: scaleX(1); opacity: 0.7; }
    100% { transform: scaleX(0.2); opacity: 0.4; }
}

/* base.html's html.preload rule suppresses ALL animations during boot —
   exactly when this loader is on screen. Punch through for the loader only
   (id selector outranks `html.preload *`). */
html.preload #page-loader .loader-ball {
    animation: enneBounce 0.5s alternate infinite ease !important;
}
html.preload #page-loader .loader-shadow {
    animation: enneShadowPulse 0.5s alternate infinite ease !important;
}
html.preload #page-loader.loader-quiet .loader-inner {
    animation: loaderReveal 0.3s ease 0.35s forwards !important;
}

@media (prefers-reduced-motion: reduce) {
    /* Controller hides the loader immediately under reduced motion; if a
       frame does paint, show a static composition instead of the bounce. */
    .loader-ball,
    .loader-shadow {
        animation: none !important;
    }
    .loader-ball { top: 20px; }
    #page-loader.loader-quiet .loader-inner {
        animation: none !important;
        opacity: 0;
    }
}

/* ============================================
   SKELETON SHIMMER — list-page loading states
   (templates/partials/_skeleton_cards.html). Cards mimic list-card
   geometry; the page's render pass wipes them via container.innerHTML
   when data lands, so no JS is involved.
   ============================================ */
.skel-group {
    display: contents; /* cards participate in the surrounding grid */
}

.skel-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 18px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-height: 150px;
}

.skel-row {
    display: flex;
    align-items: center;
    gap: 12px;
}

.skel-col {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.skel {
    position: relative;
    overflow: hidden;
    border-radius: 6px;
    background: color-mix(in srgb, var(--foreground) 7%, transparent);
}

.skel::after {
    content: '';
    position: absolute;
    inset: 0;
    transform: translateX(-100%);
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.55), transparent);
    animation: skelShimmer 1.6s ease-in-out infinite;
}

[data-theme="dark"] .skel::after {
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.07), transparent);
}

.skel-avatar {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    flex-shrink: 0;
}

.skel-line {
    height: 12px;
}

/* List-row variant (tasks list and other row layouts) */
.skel-list-row {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 15px 16px;
    display: flex;
    align-items: center;
    gap: 14px;
    width: 100%;
}

.skel-dot {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    flex-shrink: 0;
}

.skel-chip {
    width: 64px;
    height: 20px;
    border-radius: 999px;
    flex-shrink: 0;
}

@keyframes skelShimmer {
    to { transform: translateX(100%); }
}

/* "Load more" footer under paginated list grids */
.load-more-wrap {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    margin: 24px 0 8px;
}

.load-more-count {
    font-size: 12px;
    color: var(--muted-foreground);
}

@media (prefers-reduced-motion: reduce) {
    .skel::after {
        animation: none;
    }
}
