/* The Flock Loading Animations - Purple Gradient Design System */

/* Base loading overlay */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    /* Soft frosted scrim over the page — reads as a quick transition, not a splash takeover */
    background: rgba(245, 246, 247, 0.72);
    -webkit-backdrop-filter: blur(10px) saturate(1.08);
    backdrop-filter: blur(10px) saturate(1.08);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: var(--z-notification);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.25s ease, visibility 0.25s ease;
    pointer-events: none !important; /* DEFAULT: Never block clicks */
}

/* Slim top progress bar — the primary, low-intrusion "working" cue */
.loading-bar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    overflow: hidden;
    background: transparent;
}
.loading-bar span {
    display: block;
    height: 100%;
    width: 38%;
    border-radius: 0 3px 3px 0;
    background: linear-gradient(90deg, var(--v2-primary, #9333ea), #3b82f6);
    animation: loadingBarSlide 1.05s cubic-bezier(0.4, 0, 0.2, 1) infinite;
}
@keyframes loadingBarSlide {
    0%   { transform: translateX(-110%); }
    100% { transform: translateX(360%); }
}

/* Brand spinner ring */
.loading-ring {
    width: 46px;
    height: 46px;
    margin: 0 auto 1.1rem;
}
.loading-ring svg {
    width: 100%;
    height: 100%;
    animation: loadingRingSpin 0.85s linear infinite;
}
.loading-ring-track {
    fill: none;
    stroke: var(--v2-outline-variant, rgba(171, 173, 174, 0.3));
    stroke-width: 4.5;
}
.loading-ring-indicator {
    fill: none;
    stroke: var(--v2-primary, #9333ea);
    stroke-width: 4.5;
    stroke-linecap: round;
    stroke-dasharray: 132;
    stroke-dashoffset: 90;
}
@keyframes loadingRingSpin {
    to { transform: rotate(360deg); }
}
@media (prefers-reduced-motion: reduce) {
    .loading-ring svg { animation-duration: 1.6s; }
    .loading-bar span { animation-duration: 2s; }
}

.loading-overlay.active {
    display: flex;
    opacity: 1;
    visibility: visible;
    pointer-events: auto; /* Only allow clicks when explicitly active */
}

.loading-overlay.hidden {
    opacity: 0 !important;
    visibility: hidden !important;
    pointer-events: none !important;
    display: none !important;
    z-index: -1 !important; /* Force it below everything when hidden */
}

/* Loading container — clean surface card on the frosted scrim */
.loading-container {
    text-align: center;
    padding: 2rem 2.25rem;
    max-width: 320px;
    background: var(--v2-surface-lowest, #ffffff);
    border-radius: var(--v2-radius, 1rem);
    border: 1px solid var(--v2-outline-variant, rgba(171, 173, 174, 0.2));
    box-shadow: 0 12px 40px rgba(15, 23, 42, 0.16);
    color: var(--v2-on-surface, #2c2f30);
    animation: loadingCardIn 0.25s ease both;
}
@keyframes loadingCardIn {
    from { opacity: 0; transform: translateY(6px) scale(0.985); }
    to   { opacity: 1; transform: none; }
}

/* Church themed spinner */
.church-spinner {
    width: 80px;
    height: 80px;
    margin: 0 auto 1.5rem;
    position: relative;
    animation: rotate 2s linear infinite;
}

.church-cross {
    width: 60px;
    height: 60px;
    position: relative;
    margin: 10px auto;
}

.cross-vertical {
    width: 8px;
    height: 50px;
    background: linear-gradient(45deg, rgba(255, 255, 255, 0.9), rgba(255, 255, 255, 0.7));
    position: absolute;
    left: 50%;
    top: 5px;
    transform: translateX(-50%);
    border-radius: 4px;
    animation: glow 2s ease-in-out infinite alternate;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.cross-horizontal {
    width: 30px;
    height: 8px;
    background: linear-gradient(45deg, rgba(255, 255, 255, 0.9), rgba(255, 255, 255, 0.7));
    position: absolute;
    left: 50%;
    top: 20px;
    transform: translateX(-50%);
    border-radius: 4px;
    animation: glow 2s ease-in-out infinite alternate;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

@keyframes rotate {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

@keyframes glow {
    from { 
        box-shadow: 0 0 15px rgba(255, 255, 255, 0.4);
        opacity: 0.8;
    }
    to { 
        box-shadow: 0 0 25px rgba(255, 255, 255, 0.7);
        opacity: 1;
    }
}

/* Text-based spinner */
.text-spinner {
    position: relative;
    z-index: var(--z-content-above);
    margin-bottom: 2rem;
    text-align: center;
    font-family: 'Inter', Arial, sans-serif;
}

.spinner-text {
    font-size: 1.8rem;
    font-weight: 700;
    color: white;
    margin-bottom: 0.5rem;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.spinner-dots {
    font-size: 2.2rem;
    color: rgba(255, 255, 255, 0.9);
    font-weight: bold;
}

.spinner-dots .dot {
    animation: dotBounce 1.4s ease-in-out infinite both;
    display: inline-block;
}

.spinner-dots .dot:nth-child(1) {
    animation-delay: -0.32s;
}

.spinner-dots .dot:nth-child(2) {
    animation-delay: -0.16s;
}

.spinner-dots .dot:nth-child(3) {
    animation-delay: 0s;
}

@keyframes dotBounce {
    0%, 80%, 100% {
        transform: scale(0.8);
        opacity: 0.5;
    }
    40% {
        transform: scale(1.2);
        opacity: 1;
    }
}

/* Flock loading animation */
.flock-animation {
    width: 120px;
    height: 80px;
    margin: 0 auto 1.5rem;
    position: relative;
}

.sheep {
    width: 20px;
    height: 20px;
    background: #f8f9fa;
    border-radius: 50%;
    position: absolute;
    animation: flock-move 3s ease-in-out infinite;
    border: 2px solid #dee2e6;
}

.sheep:nth-child(1) {
    animation-delay: 0s;
    left: 0;
}

.sheep:nth-child(2) {
    animation-delay: 0.3s;
    left: 25px;
}

.sheep:nth-child(3) {
    animation-delay: 0.6s;
    left: 50px;
}

.sheep:nth-child(4) {
    animation-delay: 0.9s;
    left: 75px;
}

.sheep:nth-child(5) {
    animation-delay: 1.2s;
    left: 100px;
}

@keyframes flock-move {
    0%, 100% { 
        transform: translateY(0) scale(1);
        opacity: 0.6;
    }
    50% { 
        transform: translateY(-15px) scale(1.1);
        opacity: 1;
    }
}

/* Prayer hands animation */
.prayer-hands {
    width: 60px;
    height: 80px;
    margin: 0 auto 1.5rem;
    position: relative;
}

.hand {
    width: 25px;
    height: 60px;
    background: linear-gradient(145deg, #f8d7da, #f1c6c8);
    border-radius: 15px 15px 8px 8px;
    position: absolute;
    top: 10px;
    animation: pray 2s ease-in-out infinite;
}

.hand.left {
    left: 10px;
    transform-origin: bottom center;
}

.hand.right {
    right: 10px;
    transform-origin: bottom center;
}

@keyframes pray {
    0%, 100% { 
        transform: rotate(0deg);
        box-shadow: 0 5px 15px rgba(122, 31, 31, 0.2);
    }
    50% { 
        transform: rotate(-5deg);
        box-shadow: 0 8px 20px rgba(122, 31, 31, 0.3);
    }
}

/* Heart pulse animation */
.heart-pulse {
    width: 60px;
    height: 60px;
    margin: 0 auto 1.5rem;
    position: relative;
}

.heart {
    width: 50px;
    height: 45px;
    position: relative;
    transform: rotate(-45deg);
    animation: heartbeat 1.5s ease-in-out infinite;
}

.heart:before,
.heart:after {
    content: '';
    width: 26px;
    height: 40px;
    position: absolute;
    left: 25px;
    top: 0;
    background: #c084fc;
    border-radius: 25px 25px 0 0;
    transform: rotate(-45deg);
    transform-origin: 0 100%;
}

.heart:after {
    left: 0;
    transform: rotate(45deg);
    transform-origin: 100% 100%;
}

@keyframes heartbeat {
    0%, 100% { 
        transform: rotate(-45deg) scale(1);
    }
    50% { 
        transform: rotate(-45deg) scale(1.1);
    }
}

/* Wave loading animation */
.wave-loading {
    width: 100px;
    height: 40px;
    margin: 0 auto 1.5rem;
    display: flex;
    align-items: end;
    justify-content: space-between;
}

.wave-bar {
    width: 8px;
    height: 20px;
    background: linear-gradient(45deg, rgba(255, 255, 255, 0.9), rgba(255, 255, 255, 0.7));
    border-radius: 4px;
    animation: wave 1.2s ease-in-out infinite;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.wave-bar:nth-child(1) { animation-delay: 0s; }
.wave-bar:nth-child(2) { animation-delay: 0.1s; }
.wave-bar:nth-child(3) { animation-delay: 0.2s; }
.wave-bar:nth-child(4) { animation-delay: 0.3s; }
.wave-bar:nth-child(5) { animation-delay: 0.4s; }
.wave-bar:nth-child(6) { animation-delay: 0.5s; }

@keyframes wave {
    0%, 40%, 100% { 
        transform: scaleY(0.4);
        opacity: 0.5;
    }
    20% { 
        transform: scaleY(1);
        opacity: 1;
    }
}

/* Loading text animations */
.loading-text {
    font-family: 'Inter', sans-serif;
    margin-bottom: 1.5rem;
}

.loading-title,
.loading-overlay .loading-title,
body:not(.hangout-app) .loading-overlay .loading-title {
    font-family: var(--v2-font-headline, 'Space Grotesk'), sans-serif;
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--v2-on-surface, #2c2f30) !important;
    margin: 0 0 0.35rem;
    text-shadow: none;
    letter-spacing: 0;
}

.loading-message {
    font-family: var(--v2-font-body, 'Inter'), sans-serif;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--v2-on-surface-variant, #595c5d);
    margin-bottom: 0.15rem;
    animation: none;
}

.loading-subtitle {
    font-family: var(--v2-font-body, 'Inter'), sans-serif;
    font-size: 0.8rem;
    color: var(--v2-on-surface-variant, #595c5d);
    opacity: 0.75;
    margin: 0;
}

/* Dark mode — card colours flip via --v2-* tokens; the scrim + shadow need explicit dark values */
[data-theme="dark"] .loading-overlay {
    background: rgba(15, 18, 20, 0.74);
}
[data-theme="dark"] .loading-container {
    border-color: rgba(255, 255, 255, 0.08);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
}
@media (prefers-color-scheme: dark) {
    [data-theme="auto"] .loading-overlay {
        background: rgba(15, 18, 20, 0.74);
    }
    [data-theme="auto"] .loading-container {
        border-color: rgba(255, 255, 255, 0.08);
        box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
    }
}

@keyframes fadeInOut {
    0%, 100% { opacity: 0.6; }
    50% { opacity: 1; }
}

/* Progress bar animation */
.progress-container {
    width: 200px;
    height: 4px;
    background: #e9ecef;
    border-radius: 2px;
    margin: 1.5rem auto;
    overflow: hidden;
    position: relative;
}

.progress-bar {
    height: 100%;
    background: linear-gradient(90deg, #7a1f1f, #b23a3a, #7a1f1f);
    background-size: 200% 100%;
    border-radius: 2px;
    animation: progressMove 2s linear infinite;
    width: 60%;
}

@keyframes progressMove {
    0% { 
        transform: translateX(-100%);
        background-position: 200% 0;
    }
    100% { 
        transform: translateX(250%);
        background-position: -200% 0;
    }
}

/* Specific loading states */
.loading-members .flock-animation { display: block; }
.loading-services .church-spinner { display: block; }
.loading-prayer .prayer-hands { display: block; }
.loading-reports .wave-loading { display: block; }
.loading-general .heart-pulse { display: block; }

/* Hide the legacy themed animations (not injected by the current overlay markup) */
.loading-container .church-spinner,
.loading-container .flock-animation,
.loading-container .prayer-hands,
.loading-container .wave-loading,
.loading-container .heart-pulse {
    display: none;
}

/* Skeleton loading for cards */
.skeleton {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: loading 1.5s infinite;
}

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

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

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

.skeleton-text.long {
    width: 100%;
}

.skeleton-avatar {
    width: 50px;
    height: 50px;
    border-radius: 50%;
}

.skeleton-card {
    padding: 1rem;
    border-radius: 8px;
    margin-bottom: 1rem;
    border: 1px solid #e9ecef;
}

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

/* Floating elements animation */
.floating-elements {
    position: absolute;
    width: 100%;
    height: 100%;
    pointer-events: none;
    overflow: hidden;
}

.floating-element {
    position: absolute;
    opacity: 0.1;
    animation: float 8s ease-in-out infinite;
}

.floating-element.cross {
    width: 20px;
    height: 20px;
    color: #7a1f1f;
}

.floating-element:nth-child(1) {
    left: 10%;
    animation-delay: 0s;
    animation-duration: 6s;
}

.floating-element:nth-child(2) {
    left: 20%;
    animation-delay: 1s;
    animation-duration: 8s;
}

.floating-element:nth-child(3) {
    left: 70%;
    animation-delay: 2s;
    animation-duration: 7s;
}

.floating-element:nth-child(4) {
    left: 80%;
    animation-delay: 3s;
    animation-duration: 9s;
}

@keyframes float {
    0%, 100% {
        transform: translateY(100vh) rotate(0deg);
        opacity: 0;
    }
    10%, 90% {
        opacity: 0.1;
    }
    50% {
        opacity: 0.2;
        transform: translateY(-20px) rotate(180deg);
    }
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .loading-container {
        padding: 1.5rem;
    }
    
    .church-spinner,
    .flock-animation {
        transform: scale(0.8);
    }
    
    .loading-text {
        font-size: 1rem;
    }
    
    .progress-container {
        width: 150px;
    }
}

/* ===== DARK MODE OVERRIDES ===== */

/* Explicit dark theme */
[data-theme="dark"] .sheep {
    background: #2a2d3a;
    border-color: #3a3f4d;
}

[data-theme="dark"] .progress-container {
    background: #3a3f4d;
}

[data-theme="dark"] .skeleton {
    background: linear-gradient(90deg, #2a2d3a 25%, #3a3f4d 50%, #2a2d3a 75%);
    background-size: 200% 100%;
}

[data-theme="dark"] .skeleton-card {
    border-color: #3a3f4d;
}

/* Auto theme respecting system preference */
@media (prefers-color-scheme: dark) {
    [data-theme="auto"] .sheep {
        background: #2a2d3a;
        border-color: #3a3f4d;
    }

    [data-theme="auto"] .progress-container {
        background: #3a3f4d;
    }

    [data-theme="auto"] .skeleton {
        background: linear-gradient(90deg, #2a2d3a 25%, #3a3f4d 50%, #2a2d3a 75%);
        background-size: 200% 100%;
    }

    [data-theme="auto"] .skeleton-card {
        border-color: #3a3f4d;
    }
}