/* ==========================================================================
   Loading States — Spinners, Skeletons, Page Transitions
   Extracted from main.css for modularity (v0.8.0)
   ========================================================================== */

/* --------------------------------------------------------------------------
   Loading Spinner
   -------------------------------------------------------------------------- */
.loading {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 2rem;
}

.loading-spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--border-color);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

/* --------------------------------------------------------------------------
   Page-loading overlay
   -------------------------------------------------------------------------- */
.page-loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
}

.page-loading-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.page-loading-overlay .loading-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border-color, rgba(35, 40, 32, 0.09));
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

/* --------------------------------------------------------------------------
   Keyframes
   -------------------------------------------------------------------------- */
@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(8px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* --------------------------------------------------------------------------
   Skeleton Loading Placeholders
   -------------------------------------------------------------------------- */
@keyframes shimmer {
    0% {
        background-position: -400px 0;
    }

    100% {
        background-position: 400px 0;
    }
}

.skeleton {
    background: linear-gradient(90deg,
            var(--border-light, rgba(35, 40, 32, 0.05)) 25%,
            var(--card-background) 50%,
            var(--border-light, rgba(35, 40, 32, 0.05)) 75%);
    background-size: 800px 100%;
    animation: shimmer 1.5s infinite linear;
    border-radius: var(--border-radius-sm);
}

.skeleton-text {
    height: 0.9rem;
    margin-bottom: 8px;
    border-radius: 4px;
}

.skeleton-text.short {
    width: 40%;
}

.skeleton-text.medium {
    width: 70%;
}

.skeleton-heading {
    height: 1.5rem;
    width: 50%;
    margin-bottom: 12px;
    border-radius: 4px;
}

.skeleton-card {
    background: var(--card-background);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    padding: 20px;
}

.skeleton-stat {
    height: 70px;
    border-radius: var(--border-radius);
}

.skeleton-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    flex-shrink: 0;
}

.skeleton-badge {
    height: 24px;
    width: 80px;
    border-radius: var(--border-radius);
    display: inline-block;
}

/* --------------------------------------------------------------------------
   Page Transition Animation
   -------------------------------------------------------------------------- */
.page-header,
.stats-bar,
.stats-grid,
.dashboard-grid,
.list-grid,
.entries-grid,
.entry-detail,
.relationship-detail,
.prompt-detail,
.filter-sidebar,
.emotion-chart,
.insights-list {
    animation: pageContentFadeIn var(--transition-slow, 0.3s) ease-out;
}

@keyframes pageContentFadeIn {
    from {
        opacity: 0;
        transform: translateY(6px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Staggered animation for cards in grids */
.list-grid .list-card,
.entries-grid .entry-card,
.stats-grid .stat-card,
.insights-list .card-link {
    animation: pageContentFadeIn 0.3s ease-out backwards;
}

.list-grid .list-card:nth-child(1),
.entries-grid .entry-card:nth-child(1),
.stats-grid .stat-card:nth-child(1),
.insights-list .card-link:nth-child(1) {
    animation-delay: 0.03s;
}

.list-grid .list-card:nth-child(2),
.entries-grid .entry-card:nth-child(2),
.stats-grid .stat-card:nth-child(2),
.insights-list .card-link:nth-child(2) {
    animation-delay: 0.06s;
}

.list-grid .list-card:nth-child(3),
.entries-grid .entry-card:nth-child(3),
.stats-grid .stat-card:nth-child(3),
.insights-list .card-link:nth-child(3) {
    animation-delay: 0.09s;
}

.list-grid .list-card:nth-child(4),
.entries-grid .entry-card:nth-child(4),
.stats-grid .stat-card:nth-child(4),
.insights-list .card-link:nth-child(4) {
    animation-delay: 0.12s;
}

.list-grid .list-card:nth-child(5),
.entries-grid .entry-card:nth-child(5),
.stats-grid .stat-card:nth-child(5),
.insights-list .card-link:nth-child(5) {
    animation-delay: 0.15s;
}

.list-grid .list-card:nth-child(6),
.entries-grid .entry-card:nth-child(6),
.stats-grid .stat-card:nth-child(6),
.insights-list .card-link:nth-child(6) {
    animation-delay: 0.18s;
}

/* Respect reduced-motion preferences */
@media (prefers-reduced-motion: reduce) {
    .skeleton {
        animation: none;
    }

    .page-header,
    .stats-bar,
    .stats-grid,
    .dashboard-grid,
    .list-grid,
    .entries-grid,
    .entry-detail,
    .relationship-detail,
    .prompt-detail,
    .filter-sidebar,
    .emotion-chart,
    .insights-list,
    .list-grid .list-card,
    .entries-grid .entry-card,
    .stats-grid .stat-card,
    .insights-list .card-link {
        animation: none;
    }
}