/**
 * Loading Indicators and Overlays for Payment Portal
 *
 * Provides accessible loading states, spinners, and overlay components
 * for async operations and form submissions.
 */

/* ===== Loading Overlay ===== */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.9);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    opacity: 1;
    transition: opacity 0.3s ease;
}

body.dark-mode .loading-overlay {
    background: rgba(24, 24, 27, 0.9);
}

.loading-overlay.fade-out {
    opacity: 0;
    pointer-events: none;
}

.loading-overlay-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
}

.loading-overlay-text {
    color: var(--text-primary-color);
    font-size: 16px;
    font-weight: 500;
    text-align: center;
}

/* ===== Spinner Variations ===== */

/* Primary spinner - used in loading overlay */
.spinner {
    width: 50px;
    height: 50px;
    border: 4px solid var(--border-color);
    border-top: 4px solid var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

/* Small spinner - for buttons */
.spinner-small {
    width: 20px;
    height: 20px;
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-top: 3px solid white;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    display: inline-block;
    vertical-align: middle;
}

/* Medium spinner */
.spinner-medium {
    width: 35px;
    height: 35px;
    border: 3px solid var(--border-color);
    border-top: 3px solid var(--primary-color);
    border-radius: 50%;
    animation: spin 0.9s linear infinite;
}

/* Large spinner */
.spinner-large {
    width: 70px;
    height: 70px;
    border: 5px solid var(--border-color);
    border-top: 5px solid var(--primary-color);
    border-radius: 50%;
    animation: spin 1.2s linear infinite;
}

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

/* ===== Pulsing Dot Spinner ===== */
.spinner-dots {
    display: flex;
    gap: 8px;
    align-items: center;
}

.spinner-dots .dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background-color: var(--primary-color);
    animation: pulse 1.4s ease-in-out infinite;
}

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

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

@keyframes pulse {
    0%, 80%, 100% {
        opacity: 0.3;
        transform: scale(0.8);
    }
    40% {
        opacity: 1;
        transform: scale(1);
    }
}

/* ===== Progress Bar ===== */
.progress-bar-container {
    width: 100%;
    max-width: 400px;
    height: 8px;
    background-color: var(--border-color);
    border-radius: 4px;
    overflow: hidden;
    margin: 20px 0;
}

.progress-bar {
    height: 100%;
    background-color: var(--primary-color);
    transition: width 0.3s ease;
    border-radius: 4px;
}

.progress-bar.indeterminate {
    width: 30%;
    animation: progress-indeterminate 1.5s ease-in-out infinite;
}

@keyframes progress-indeterminate {
    0% {
        transform: translateX(-100%);
    }
    100% {
        transform: translateX(400%);
    }
}

/* ===== Skeleton Loaders ===== */
.skeleton {
    background: linear-gradient(
        90deg,
        var(--surface-alt-color) 25%,
        var(--border-color) 50%,
        var(--surface-alt-color) 75%
    );
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s ease-in-out infinite;
    border-radius: 4px;
}

.skeleton-text {
    height: 16px;
    margin-bottom: 8px;
}

.skeleton-title {
    height: 24px;
    width: 60%;
    margin-bottom: 16px;
}

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

.skeleton-button {
    height: 40px;
    width: 120px;
}

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

/* ===== Button Loading States ===== */
.btn-loading {
    position: relative;
    color: transparent !important;
    pointer-events: none;
    cursor: not-allowed;
}

.btn-loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 20px;
    height: 20px;
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-top: 3px solid white;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.btn-secondary.btn-loading::after {
    border: 3px solid var(--border-color);
    border-top: 3px solid var(--text-primary-color);
}

/* ===== Inline Loading State ===== */
.loading-inline {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    color: var(--text-secondary-color);
    font-size: 14px;
}

.loading-inline .spinner-small {
    border-color: var(--border-color);
    border-top-color: var(--primary-color);
}

/* ===== Form Field Loading State ===== */
.form-group.loading {
    position: relative;
}

.form-group.loading::after {
    content: '';
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    width: 16px;
    height: 16px;
    border: 2px solid var(--border-color);
    border-top: 2px solid var(--primary-color);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

.form-group.loading input,
.form-group.loading select {
    padding-right: 40px;
}

/* ===== Card Loading State ===== */
.card-loading {
    position: relative;
    min-height: 200px;
    overflow: hidden;
}

.card-loading::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.8);
    z-index: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

body.dark-mode .card-loading::before {
    background: rgba(24, 24, 27, 0.8);
}

.card-loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 40px;
    height: 40px;
    border: 4px solid var(--border-color);
    border-top: 4px solid var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    z-index: 2;
}

/* ===== Shimmer Effect ===== */
.shimmer {
    background: linear-gradient(
        90deg,
        transparent,
        rgba(255, 255, 255, 0.4),
        transparent
    );
    animation: shimmer 2s infinite;
    background-size: 200% 100%;
}

body.dark-mode .shimmer {
    background: linear-gradient(
        90deg,
        transparent,
        rgba(255, 255, 255, 0.1),
        transparent
    );
}

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

/* ===== Accessibility ===== */
.loading-overlay,
.spinner,
.spinner-dots,
.progress-bar,
.btn-loading {
    /* Announce to screen readers */
}

/* Screen reader only text for loading states */
.sr-loading {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}

/* ===== Responsive Adjustments ===== */
@media (max-width: 768px) {
    .loading-overlay-text {
        font-size: 14px;
        padding: 0 20px;
    }

    .spinner {
        width: 40px;
        height: 40px;
        border-width: 3px;
    }

    .spinner-large {
        width: 60px;
        height: 60px;
        border-width: 4px;
    }
}

@media (max-width: 480px) {
    .loading-overlay-text {
        font-size: 13px;
    }

    .spinner {
        width: 35px;
        height: 35px;
    }
}

/* ===== Utility Classes ===== */
.hide-on-loading {
    transition: opacity 0.2s ease;
}

.hide-on-loading.loading {
    opacity: 0;
    pointer-events: none;
}

.blur-on-loading {
    transition: filter 0.2s ease;
}

.blur-on-loading.loading {
    filter: blur(4px);
    pointer-events: none;
}

/* Disable interactions during loading */
.no-interaction {
    pointer-events: none;
    user-select: none;
}
