/**
 * BloodLab - Modern Skeleton Loader & Shimmer UI Stylesheet
 * Hardware-accelerated, theme-adaptive (Light / Dark mode), high performance SPA loader
 * Path: assets/global/css/spa-skeleton.css
 */

:root {
    /* Base color tokens for skeletons */
    --skeleton-base: #e9eef5;
    --skeleton-highlight: #f8fafc;
    --skeleton-border: #e2e8f0;
    --skeleton-card-bg: #ffffff;
    --skeleton-duration: 1.5s;
    --skeleton-timing: cubic-bezier(0.4, 0, 0.2, 1);
    --skeleton-radius: 6px;
    --skeleton-radius-sm: 4px;
    --skeleton-radius-lg: 10px;
    --skeleton-radius-pill: 50rem;

    /* Topbar progress line loader */
    --spa-loader-height: 3px;
    --spa-loader-color: #4634ff;
    --spa-loader-color-alt: #ea5455;
    --spa-loader-glow: rgba(70, 52, 255, 0.6);
    --spa-loader-z-index: 999999;
}

/* Dark Theme / Dark Mode Overrides */
@media (prefers-color-scheme: dark) {
    :root {
        --skeleton-base: #1e2640;
        --skeleton-highlight: #2c3656;
        --skeleton-border: #2b3552;
        --skeleton-card-bg: #141b2e;
    }
}

[data-theme="dark"],
.dark-theme,
.dark-mode,
.theme--dark,
body.dark {
    --skeleton-base: #1e2640;
    --skeleton-highlight: #2c3656;
    --skeleton-border: #2b3552;
    --skeleton-card-bg: #141b2e;
}

/* Contextual dark background support */
.bg--dark .skeleton,
.bg-dark .skeleton,
.dark--overlay .skeleton {
    --skeleton-base: rgba(255, 255, 255, 0.08);
    --skeleton-highlight: rgba(255, 255, 255, 0.18);
    --skeleton-border: rgba(255, 255, 255, 0.12);
}

/* ==========================================================================
   1. HARDWARE ACCELERATED SHIMMER ANIMATION & BASE PRIMITIVES
   ========================================================================== */

@keyframes spaShimmerAnimation {
    0% {
        background-position: -200% 0;
    }
    100% {
        background-position: 200% 0;
    }
}

@keyframes spaPulseAnimation {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.45;
    }
}

/* Base Skeleton Element */
.skeleton,
.skeleton-bone {
    background-color: var(--skeleton-base);
    background-image: linear-gradient(
        90deg,
        var(--skeleton-base) 0%,
        var(--skeleton-highlight) 35%,
        var(--skeleton-base) 70%
    );
    background-size: 200% 100%;
    background-repeat: no-repeat;
    animation: spaShimmerAnimation var(--skeleton-duration) var(--skeleton-timing) infinite;
    border-radius: var(--skeleton-radius);
    display: inline-block;
    vertical-align: middle;
    line-height: 1;
    user-select: none;
    pointer-events: none;
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
    transform: translateZ(0);
    will-change: background-position;
}

/* Pulse variant */
.skeleton--pulse {
    animation: spaPulseAnimation var(--skeleton-duration) ease-in-out infinite;
    background-image: none;
}

/* Shape & Type Modifiers */
.skeleton-circle,
.skeleton-avatar {
    border-radius: 50% !important;
    width: 40px;
    height: 40px;
    flex-shrink: 0;
}
.skeleton-avatar--xs { width: 24px; height: 24px; }
.skeleton-avatar--sm { width: 32px; height: 32px; }
.skeleton-avatar--md { width: 44px; height: 44px; }
.skeleton-avatar--lg { width: 56px; height: 56px; }
.skeleton-avatar--xl { width: 80px; height: 80px; }

.skeleton-text {
    width: 100%;
    height: 13px;
    margin-bottom: 8px;
    border-radius: var(--skeleton-radius-sm);
}
.skeleton-text:last-child {
    margin-bottom: 0;
}
.skeleton-text--xs { height: 8px; }
.skeleton-text--sm { height: 10px; }
.skeleton-text--md { height: 14px; }
.skeleton-text--lg { height: 18px; }
.skeleton-heading   { height: 26px; border-radius: var(--skeleton-radius-sm); margin-bottom: 12px; }
.skeleton-title     { height: 20px; border-radius: var(--skeleton-radius-sm); margin-bottom: 10px; }

.skeleton-badge {
    height: 22px;
    width: 65px;
    border-radius: var(--skeleton-radius-pill);
    display: inline-block;
}

.skeleton-btn {
    height: 38px;
    width: 100px;
    border-radius: var(--skeleton-radius);
    display: inline-block;
}
.skeleton-btn--sm {
    height: 30px;
    width: 75px;
}
.skeleton-btn--icon {
    width: 32px;
    height: 32px;
    border-radius: var(--skeleton-radius-sm);
}
.skeleton-btn--block {
    width: 100%;
    height: 42px;
}

/* Width Percentage Utilities */
.skeleton--w-15  { width: 15% !important; }
.skeleton--w-20  { width: 20% !important; }
.skeleton--w-25  { width: 25% !important; }
.skeleton--w-30  { width: 30% !important; }
.skeleton--w-35  { width: 35% !important; }
.skeleton--w-40  { width: 40% !important; }
.skeleton--w-50  { width: 50% !important; }
.skeleton--w-60  { width: 60% !important; }
.skeleton--w-70  { width: 70% !important; }
.skeleton--w-75  { width: 75% !important; }
.skeleton--w-80  { width: 80% !important; }
.skeleton--w-85  { width: 85% !important; }
.skeleton--w-90  { width: 90% !important; }
.skeleton--w-100 { width: 100% !important; }


/* ==========================================================================
   2. TOPBAR PROGRESS / LOADING INDICATOR (YouTube / NProgress style)
   ========================================================================== */

.spa-progress-bar {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: var(--spa-loader-height);
    background-color: transparent;
    z-index: var(--spa-loader-z-index);
    pointer-events: none;
    overflow: hidden;
    opacity: 0;
    transition: opacity 0.25s ease-in-out;
}

.spa-progress-bar.is-loading,
.spa-progress-bar.active {
    opacity: 1;
}

.spa-progress-bar__inner {
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    width: 0%;
    background: linear-gradient(90deg, var(--spa-loader-color, #4634ff), var(--spa-loader-color-alt, #ea5455));
    border-radius: 0 2px 2px 0;
    box-shadow: 0 0 10px var(--spa-loader-glow);
    transition: width 0.3s cubic-bezier(0.1, 0.9, 0.2, 1);
    will-change: width, opacity;
}

/* Glowing right edge (peg) */
.spa-progress-bar__peg {
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: 80px;
    box-shadow: 0 0 12px var(--spa-loader-color, #4634ff), 0 0 6px var(--spa-loader-color-alt, #ea5455);
    border-radius: 50%;
    transform: rotate(3deg) translate(0px, -4px);
    opacity: 0.9;
}

/* Smooth indeterminate fallback animation */
.spa-progress-bar--indeterminate .spa-progress-bar__inner {
    width: 100%;
    animation: spaProgressIndeterminate 1.8s infinite linear;
    transform-origin: 0% 50%;
}

@keyframes spaProgressIndeterminate {
    0% {
        transform: translateX(-100%);
    }
    50% {
        transform: translateX(25%);
    }
    100% {
        transform: translateX(110%);
    }
}

/* Integration compatibility with NProgress if used */
#nprogress {
    pointer-events: none;
}
#nprogress .bar {
    background: linear-gradient(90deg, var(--spa-loader-color, #4634ff), var(--spa-loader-color-alt, #ea5455)) !important;
    position: fixed;
    z-index: var(--spa-loader-z-index);
    top: 0;
    left: 0;
    width: 100%;
    height: var(--spa-loader-height);
}
#nprogress .peg {
    box-shadow: 0 0 10px var(--spa-loader-color, #4634ff), 0 0 5px var(--spa-loader-color, #4634ff) !important;
}


/* ==========================================================================
   3. CARD SKELETON
   ========================================================================== */

.skeleton-card {
    background: var(--skeleton-card-bg);
    border: 1px solid var(--skeleton-border);
    border-radius: var(--skeleton-radius-lg);
    padding: 1.5rem;
    box-shadow: 0 0.75rem 1.5rem rgba(18, 38, 63, 0.03);
    position: relative;
    overflow: hidden;
    margin-bottom: 1.5rem;
}

.skeleton-card__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-bottom: 1.25rem;
    margin-bottom: 1.25rem;
    border-bottom: 1px solid var(--skeleton-border);
}

.skeleton-card__title-group {
    display: flex;
    align-items: center;
    gap: 0.85rem;
    flex-grow: 1;
}

.skeleton-card__titles {
    display: flex;
    flex-direction: column;
    width: 60%;
    gap: 6px;
}

.skeleton-card__body {
    padding: 0;
}

.skeleton-card__icon-box {
    width: 52px;
    height: 52px;
    border-radius: var(--skeleton-radius);
    flex-shrink: 0;
}

.skeleton-card__metric {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin: 1rem 0;
}

.skeleton-card__footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-top: 1.25rem;
    margin-top: 1.25rem;
    border-top: 1px solid var(--skeleton-border);
}


/* ==========================================================================
   4. TABLE SKELETON
   ========================================================================== */

.skeleton-table-wrapper {
    background: var(--skeleton-card-bg);
    border-radius: var(--skeleton-radius-lg);
    border: 1px solid var(--skeleton-border);
    box-shadow: 0 0.75rem 1.5rem rgba(18, 38, 63, 0.03);
    overflow: hidden;
    margin-bottom: 1.5rem;
}

.skeleton-table {
    width: 100%;
    border-collapse: collapse;
}

.skeleton-table th,
.skeleton-table td {
    padding: 14px 20px;
    vertical-align: middle;
    border-bottom: 1px solid var(--skeleton-border);
}

.skeleton-table thead th {
    background-color: var(--skeleton-base);
    opacity: 0.85;
}

/* Pulsing striped rows with varying realistic widths */
.skeleton-table tbody tr:nth-child(even) {
    background-color: rgba(0, 0, 0, 0.015);
}

.skeleton-table__cell-flex {
    display: flex;
    align-items: center;
    gap: 12px;
}

.skeleton-table__cell-stack {
    display: flex;
    flex-direction: column;
    gap: 6px;
    width: 100%;
}

.skeleton-table__actions {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    justify-content: flex-end;
}


/* ==========================================================================
   5. FORM SKELETON
   ========================================================================== */

.skeleton-form {
    background: var(--skeleton-card-bg);
    border-radius: var(--skeleton-radius-lg);
    border: 1px solid var(--skeleton-border);
    padding: 1.75rem;
    box-shadow: 0 0.75rem 1.5rem rgba(18, 38, 63, 0.03);
    margin-bottom: 1.5rem;
}

.skeleton-form-group {
    margin-bottom: 1.5rem;
    display: flex;
    flex-direction: column;
}

.skeleton-label {
    height: 14px;
    width: 28%;
    margin-bottom: 8px;
    border-radius: var(--skeleton-radius-sm);
}

.skeleton-input {
    height: 46px;
    width: 100%;
    border-radius: var(--skeleton-radius);
    border: 1px solid transparent;
}

.skeleton-textarea {
    height: 110px;
    width: 100%;
    border-radius: var(--skeleton-radius);
}

.skeleton-form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 1.5rem;
}

.skeleton-form-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 12px;
    margin-top: 1.5rem;
    padding-top: 1.25rem;
    border-top: 1px solid var(--skeleton-border);
}


/* ==========================================================================
   6. DASHBOARD GRID & WIDGET SKELETON
   ========================================================================== */

.skeleton-dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 1.5rem;
    margin-bottom: 1.75rem;
}

/* Metric / Widget Skeleton (matching widget-seven / admin dashboard widgets) */
.skeleton-widget {
    background: var(--skeleton-card-bg);
    border: 1px solid var(--skeleton-border);
    border-radius: var(--skeleton-radius-lg);
    padding: 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    box-shadow: 0 0.75rem 1.5rem rgba(18, 38, 63, 0.03);
    position: relative;
    overflow: hidden;
}

.skeleton-widget__content {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-grow: 1;
}

.skeleton-widget__icon {
    width: 50px;
    height: 50px;
    border-radius: var(--skeleton-radius);
    flex-shrink: 0;
}

.skeleton-widget__details {
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex-grow: 1;
}

.skeleton-widget__title {
    height: 12px;
    width: 55%;
    border-radius: var(--skeleton-radius-sm);
}

.skeleton-widget__amount {
    height: 24px;
    width: 40%;
    border-radius: var(--skeleton-radius-sm);
}

.skeleton-widget__arrow {
    width: 14px;
    height: 14px;
    border-radius: var(--skeleton-radius-sm);
    flex-shrink: 0;
}

/* Chart Skeleton */
.skeleton-chart-card {
    background: var(--skeleton-card-bg);
    border: 1px solid var(--skeleton-border);
    border-radius: var(--skeleton-radius-lg);
    padding: 1.5rem;
    box-shadow: 0 0.75rem 1.5rem rgba(18, 38, 63, 0.03);
    margin-bottom: 1.75rem;
}

.skeleton-chart-card__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.5rem;
}

.skeleton-chart-card__body {
    display: flex;
    flex-direction: column;
    height: 280px;
    justify-content: flex-end;
    gap: 12px;
    padding-top: 1rem;
    position: relative;
}

.skeleton-chart-bars {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    height: 220px;
    gap: 12px;
    padding: 0 10px;
}

.skeleton-chart-bar {
    width: 100%;
    border-radius: var(--skeleton-radius-sm) var(--skeleton-radius-sm) 0 0;
}

/* Recent List Skeleton */
.skeleton-recent-list {
    display: flex;
    flex-direction: column;
}

.skeleton-recent-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 0;
    border-bottom: 1px solid var(--skeleton-border);
}

.skeleton-recent-item:last-child {
    border-bottom: none;
    padding-bottom: 0;
}

.skeleton-recent-item__user {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-grow: 1;
}

.skeleton-recent-item__meta {
    display: flex;
    align-items: center;
    gap: 14px;
}


/* ==========================================================================
   7. ACCESSIBILITY & PERFORMANCE
   ========================================================================== */

@media (prefers-reduced-motion: reduce) {
    .skeleton,
    .skeleton-bone,
    .spa-progress-bar__inner {
        animation: none !important;
        background-image: none !important;
        opacity: 0.75 !important;
        transition: none !important;
    }
}
