/**
 * Skeleton Loading System - Clinical Precision
 * Provides visual feedback during async data loading
 * Prevents layout shift (CLS) and improves perceived performance
 * v2.0 - Medical Design System Integration
 */

/* ==========================================================================
   SKELETON ANIMATION - Shimmer Effect
   ========================================================================== */

@keyframes skeleton-pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.6;
    }
}

/* ==========================================================================
   BASE SKELETON - Core Styles (Optimized for Performance)
   ========================================================================== */

.skeleton {
    background: var(--color-bg-quaternary);
    animation: skeleton-pulse 1.5s ease-in-out infinite;
    border-radius: var(--radius-md);
    display: inline-block;
    position: relative;
    overflow: hidden;
    will-change: opacity;
}

.skeleton::after {
    content: '';
    display: block;
}

/* Disable pointer events on skeletons */
.skeleton,
.skeleton * {
    pointer-events: none;
    user-select: none;
}

/* ==========================================================================
   SKELETON VARIANTS - Size & Shape
   ========================================================================== */

/* Text Skeletons */
.skeleton-text {
    height: 1em;
    margin-bottom: 0.5em;
    border-radius: var(--radius-sm);
}

.skeleton-text--xs { width: 40%; }
.skeleton-text--sm { width: 60%; }
.skeleton-text--md { width: 80%; }
.skeleton-text--lg { width: 100%; }
.skeleton-text--full { width: 100%; }

/* Heading Skeletons */
.skeleton-heading {
    height: 1.5em;
    width: 60%;
    margin-bottom: 1em;
    border-radius: var(--radius-md);
}

.skeleton-heading--xl {
    height: 2em;
    width: 70%;
}

/* Avatar/Circle Skeletons */
.skeleton-circle {
    border-radius: 50%;
    width: 48px;
    height: 48px;
}

.skeleton-circle--sm { width: 32px; height: 32px; }
.skeleton-circle--lg { width: 64px; height: 64px; }
.skeleton-circle--xl { width: 96px; height: 96px; }

/* Rectangle Skeletons */
.skeleton-rect {
    width: 100%;
    height: 200px;
}

.skeleton-rect--sm { height: 100px; }
.skeleton-rect--md { height: 200px; }
.skeleton-rect--lg { height: 300px; }
.skeleton-rect--xl { height: 400px; }

/* Button Skeletons */
.skeleton-button {
    height: 40px;
    width: 120px;
    border-radius: var(--radius-md);
}

.skeleton-button--sm { height: 32px; width: 100px; }
.skeleton-button--lg { height: 48px; width: 160px; }
.skeleton-button--full { width: 100%; }

/* ==========================================================================
   COMPONENT-SPECIFIC SKELETONS
   ========================================================================== */

/* KPI Card Skeleton */
.skeleton-kpi {
    background: var(--color-bg-primary);
    border: 1px solid var(--color-border-light);
    border-radius: var(--radius-xl);
    padding: var(--spacing-6);
    min-height: var(--kpi-secondary-height);
}

.skeleton-kpi__label {
    height: 12px;
    width: 40%;
    margin-bottom: var(--spacing-3);
}

.skeleton-kpi__value {
    height: 48px;
    width: 60%;
    margin-bottom: var(--spacing-4);
}

.skeleton-kpi__trend {
    height: 16px;
    width: 50%;
}

/* Table Row Skeleton */
.skeleton-table-row {
    display: flex;
    gap: var(--spacing-4);
    padding: var(--spacing-4);
    border-bottom: 1px solid var(--color-border-light);
}

.skeleton-table-row__cell {
    flex: 1;
    height: 20px;
}

.skeleton-table-row__cell:first-child {
    flex: 0.5;
}

.skeleton-table-row__cell:last-child {
    flex: 0.3;
}

/* Card Skeleton */
.skeleton-card {
    background: var(--color-bg-primary);
    border: 1px solid var(--color-border-light);
    border-radius: var(--radius-xl);
    padding: var(--spacing-6);
}

.skeleton-card__header {
    display: flex;
    align-items: center;
    gap: var(--spacing-4);
    margin-bottom: var(--spacing-6);
    padding-bottom: var(--spacing-4);
    border-bottom: 1px solid var(--color-border-light);
}

.skeleton-card__title {
    height: 24px;
    width: 50%;
}

.skeleton-card__body {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-3);
}

/* Appointment Card Skeleton */
.skeleton-appointment {
    display: flex;
    gap: var(--spacing-4);
    padding: var(--spacing-4);
    background: var(--color-bg-primary);
    border: 1px solid var(--color-border-light);
    border-left-width: 4px;
    border-radius: var(--radius-lg);
    margin-bottom: var(--spacing-3);
}

.skeleton-appointment__time {
    width: 80px;
    height: 60px;
    border-radius: var(--radius-md);
}

.skeleton-appointment__content {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: var(--spacing-2);
}

.skeleton-appointment__name {
    height: 20px;
    width: 70%;
}

.skeleton-appointment__service {
    height: 16px;
    width: 50%;
}

.skeleton-appointment__meta {
    height: 14px;
    width: 40%;
}

/* Calendar Skeleton */
.skeleton-calendar {
    background: var(--color-bg-primary);
    border: 1px solid var(--color-border-light);
    border-radius: var(--radius-lg);
    padding: var(--spacing-4);
    height: var(--calendar-height-desktop);
}

.skeleton-calendar__header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--spacing-6);
}

.skeleton-calendar__title {
    height: 32px;
    width: 200px;
}

.skeleton-calendar__buttons {
    display: flex;
    gap: var(--spacing-2);
}

.skeleton-calendar__button {
    width: 80px;
    height: 36px;
    border-radius: var(--radius-md);
}

.skeleton-calendar__grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: var(--spacing-2);
}

.skeleton-calendar__day {
    aspect-ratio: 1;
    border-radius: var(--radius-md);
}

/* List Skeleton */
.skeleton-list {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-3);
}

.skeleton-list-item {
    display: flex;
    align-items: center;
    gap: var(--spacing-4);
    padding: var(--spacing-4);
    background: var(--color-bg-primary);
    border: 1px solid var(--color-border-light);
    border-radius: var(--radius-lg);
}

.skeleton-list-item__icon {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-md);
}

.skeleton-list-item__content {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: var(--spacing-2);
}

.skeleton-list-item__title {
    height: 18px;
    width: 60%;
}

.skeleton-list-item__subtitle {
    height: 14px;
    width: 40%;
}

/* ==========================================================================
   DASHBOARD-SPECIFIC SKELETONS
   ========================================================================== */

/* Admin Dashboard KPI Grid Skeleton */
.skeleton-kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: var(--spacing-6);
    margin-bottom: var(--spacing-8);
}

/* Sidebar Widget Skeleton */
.skeleton-widget {
    background: var(--color-bg-primary);
    border: 1px solid var(--color-border-light);
    border-radius: var(--radius-lg);
    padding: var(--spacing-4);
}

.skeleton-widget__header {
    display: flex;
    align-items: center;
    gap: var(--spacing-3);
    margin-bottom: var(--spacing-4);
    padding-bottom: var(--spacing-3);
    border-bottom: 1px solid var(--color-border-light);
}

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

.skeleton-widget__title {
    height: 18px;
    width: 40%;
}

.skeleton-widget__body {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-3);
}

/* ==========================================================================
   LOADING CONTAINER STATES
   ========================================================================== */

/* Loading State Wrapper */
.is-loading {
    position: relative;
    min-height: 100px;
    pointer-events: none;
}

.is-loading > *:not(.skeleton):not(.skeleton-container) {
    opacity: 0;
    visibility: hidden;
}

/* Skeleton Container */
.skeleton-container {
    position: absolute;
    inset: 0;
    z-index: 1;
}

.skeleton-container--relative {
    position: relative;
}

/* Fade-in animation when content loads */
@keyframes skeleton-fade-in {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.skeleton-loaded {
    animation: skeleton-fade-in 0.4s ease-out;
}

/* ==========================================================================
   DARK MODE ADAPTATIONS
   ========================================================================== */

[data-theme="dark"] .skeleton {
    background: linear-gradient(
        90deg,
        var(--color-bg-tertiary) 0%,
        rgba(255, 255, 255, 0.03) 20%,
        var(--color-bg-tertiary) 40%,
        var(--color-bg-tertiary) 100%
    );
}

[data-theme="dark"] .skeleton--pulse {
    background: var(--color-bg-quaternary);
}

/* ==========================================================================
   RESPONSIVE ADAPTATIONS
   ========================================================================== */

@media (max-width: 768px) {
    .skeleton-kpi-grid {
        grid-template-columns: 1fr;
        gap: var(--spacing-4);
    }

    .skeleton-calendar {
        height: var(--calendar-height-mobile);
    }

    .skeleton-appointment {
        flex-direction: column;
    }

    .skeleton-appointment__time {
        width: 100%;
        height: 40px;
    }
}

/* ==========================================================================
   REDUCED MOTION SUPPORT
   ========================================================================== */

@media (prefers-reduced-motion: reduce) {
    .skeleton {
        animation: skeleton-pulse 3s ease-in-out infinite;
    }

    .skeleton-loaded {
        animation: none;
    }
}

/* ==========================================================================
   UTILITY CLASSES
   ========================================================================== */

/* Hide content during loading */
.hidden-while-loading {
    transition: opacity 0.2s ease, visibility 0.2s ease;
}

.is-loading .hidden-while-loading {
    opacity: 0;
    visibility: hidden;
}

/* Show skeleton only during loading */
.show-while-loading {
    display: none;
}

.is-loading .show-while-loading {
    display: block;
}
