/**
 * Africa SPA System - Offline & Unstable Connection UI
 * 
 * Provides visual indicators for:
 * - Offline mode
 * - Poor connection quality (2G/3G)
 * - Pending sync items
 * - Connection recovery animations
 */

/* ============================================================
   Connection Status Bar
   ============================================================ */
#africspa-connection-status {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 9999;
    padding: 6px 16px;
    text-align: center;
    font-size: 0.85rem;
    font-weight: 600;
    transition: transform 0.3s ease, opacity 0.3s ease;
    transform: translateY(-100%);
    opacity: 0;
    pointer-events: none;
}

#africspa-connection-status.active {
    transform: translateY(0);
    opacity: 1;
    pointer-events: auto;
}

#africspa-connection-status.status-offline {
    background: linear-gradient(135deg, #dc2626 0%, #b91c1c 100%);
    color: white;
}

#africspa-connection-status.status-poor {
    background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
    color: white;
}

#africspa-connection-status.status-syncing {
    background: linear-gradient(135deg, #6366f1 0%, #4f46e5 100%);
    color: white;
}

#africspa-connection-status.status-reconnecting {
    background: linear-gradient(135deg, #06b6d4 0%, #0891b2 100%);
    color: white;
}

#africspa-connection-status .status-icon {
    margin-right: 8px;
    font-size: 1rem;
}

#africspa-connection-status .status-text {
    display: inline-block;
    vertical-align: middle;
}

#africspa-connection-status .sync-count {
    display: inline-block;
    background: rgba(255, 255, 255, 0.2);
    padding: 1px 8px;
    border-radius: 10px;
    margin-left: 8px;
    font-size: 0.75rem;
}

/* ============================================================
   Connection Quality Badge (bottom-right)
   ============================================================ */
#africspa-connection-badge {
    position: fixed;
    bottom: 80px;
    right: 16px;
    z-index: 9998;
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 0.7rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all 0.3s ease;
    cursor: default;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

#africspa-connection-badge.badge-offline {
    background: #dc2626;
    color: white;
    animation: pulse-badge 2s infinite;
}

#africspa-connection-badge.badge-poor {
    background: #f59e0b;
    color: white;
}

#africspa-connection-badge.badge-fair {
    background: #06b6d4;
    color: white;
}

#africspa-connection-badge.badge-good {
    background: #10b981;
    color: white;
}

#africspa-connection-badge .dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: currentColor;
    display: inline-block;
}

.badge-offline .dot {
    background: white;
}

@keyframes pulse-badge {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

/* ============================================================
   Sync Progress Indicator
   ============================================================ */
#africspa-sync-indicator {
    position: fixed;
    bottom: 130px;
    right: 16px;
    z-index: 9997;
    display: none;
}

#africspa-sync-indicator.active {
    display: block;
}

.sync-spinner {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 3px solid #e5e7eb;
    border-top-color: #6366f1;
    animation: spin 1s linear infinite;
    background: white;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ============================================================
   Offline Mode Overlay (for forms/data entry)
   ============================================================ */
.offline-overlay {
    position: relative;
}

.offline-overlay::after {
    content: attr(data-offline-message);
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 20px;
    font-size: 0.9rem;
    color: #374151;
    z-index: 10;
    border-radius: 8px;
    border: 2px dashed #f59e0b;
}

/* ============================================================
   Slow Connection Warning
   ============================================================ */
.slow-connection-warning {
    background: #fef3c7;
    border: 1px solid #f59e0b;
    border-radius: 8px;
    padding: 12px 16px;
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 0.85rem;
    color: #92400e;
}

.slow-connection-warning .warning-icon {
    font-size: 1.25rem;
    flex-shrink: 0;
}

/* ============================================================
   Offline-specific page styling
   ============================================================ */
.offline-page {
    min-height: 70vh;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 40px 20px;
}

.offline-page .offline-icon {
    font-size: 4rem;
    margin-bottom: 16px;
    color: #6b7280;
}

.offline-page h1 {
    font-size: 1.75rem;
    color: #1f2937;
    margin-bottom: 12px;
}

.offline-page p {
    color: #6b7280;
    max-width: 400px;
    margin: 0 auto 24px;
    line-height: 1.6;
}

/* ============================================================
   Network-dependent sections - show/hide based on connectivity
   ============================================================ */
.network-required {
    transition: opacity 0.3s ease;
}

.network-required.offline-hidden {
    opacity: 0.4;
    pointer-events: none;
}

.network-required .offline-message {
    display: none;
}

.network-required.offline-hidden .offline-message {
    display: block;
    color: #dc2626;
    font-size: 0.8rem;
    margin-top: 4px;
}

/* ============================================================
   Skeleton Loading (for slow connections)
   ============================================================ */
.skeleton {
    background: linear-gradient(90deg, 
        #e5e7eb 25%, 
        #f3f4f6 50%, 
        #e5e7eb 75%
    );
    background-size: 200% 100%;
    animation: skeleton-shimmer 1.5s infinite;
    border-radius: 4px;
}

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

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

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

.skeleton-card {
    height: 120px;
    margin-bottom: 16px;
}

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

/* ============================================================
   Responsive adjustments
   ============================================================ */
@media (max-width: 768px) {
    #africspa-connection-status {
        font-size: 0.75rem;
        padding: 4px 12px;
    }
    
    #africspa-connection-badge {
        bottom: 16px;
        right: 16px;
        font-size: 0.65rem;
        padding: 4px 10px;
    }
}

/* ============================================================
   Print styles - hide connection UI when printing
   ============================================================ */
@media print {
    #africspa-connection-status,
    #africspa-connection-badge,
    #africspa-sync-indicator {
        display: none !important;
    }
}