/* ========================================
   Reconnect UI - Modern Top Loading Bar
   نظام الطلبات - قطع الغيار
   
   Design: YouTube-style top loading bar
   Shows subtle loading animation during reconnection
   After 7 seconds: Shows helpful message
   ======================================== */

/* ===== Main Container ===== */
#reconnect-ui {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 99999;
    pointer-events: none;
    font-family: 'IBM Plex Sans Arabic', 'Inter', sans-serif;
}

/* ===== Loading Bar - YouTube Style ===== */
.reconnect-bar {
    height: 3px;
    background: linear-gradient(
        90deg,
        hsl(var(--primary) / 0.3) 0%,
        hsl(var(--primary)) 50%,
        hsl(var(--primary) / 0.3) 100%
    );
    background-size: 300% 100%;
    position: relative;
    transform: scaleX(0);
    transform-origin: left;
    transition: transform 0.3s ease-out;
}

/* Shimmer effect overlay */
.reconnect-bar::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(
        90deg,
        transparent 0%,
        rgba(255, 255, 255, 0.4) 50%,
        transparent 100%
    );
    background-size: 200% 100%;
    animation: reconnect-shimmer 1.5s infinite;
}

/* Show bar when reconnecting */
#reconnect-ui.reconnecting .reconnect-bar {
    transform: scaleX(1);
    animation: reconnect-progress 2s ease-in-out infinite;
}

/* Pulsing bar when retrying */
#reconnect-ui.retrying .reconnect-bar {
    background: linear-gradient(
        90deg,
        hsl(var(--warning) / 0.3) 0%,
        hsl(var(--warning)) 50%,
        hsl(var(--warning) / 0.3) 100%
    );
    animation: reconnect-progress 1.5s ease-in-out infinite;
}

/* Failed state - solid red */
#reconnect-ui.failed .reconnect-bar {
    background: hsl(var(--destructive));
    animation: reconnect-pulse-bar 1s ease-in-out infinite;
}

#reconnect-ui.failed .reconnect-bar::after {
    display: none;
}

/* ===== Message Toast - Slide Down ===== */
.reconnect-message {
    position: absolute;
    top: 12px;
    left: 50%;
    transform: translateX(-50%) translateY(-120px);
    background: hsl(var(--card));
    border: 1px solid hsl(var(--border));
    border-radius: 16px;
    padding: 14px 20px;
    display: flex;
    align-items: center;
    gap: 14px;
    box-shadow: 
        0 4px 6px -1px rgba(0, 0, 0, 0.1),
        0 10px 20px -5px rgba(0, 0, 0, 0.12),
        0 0 0 1px rgba(255, 255, 255, 0.05);
    pointer-events: auto;
    opacity: 0;
    transition: 
        transform 0.5s cubic-bezier(0.34, 1.56, 0.64, 1),
        opacity 0.4s ease;
    max-width: calc(100vw - 32px);
    backdrop-filter: blur(8px);
}

/* Show message with spring animation */
#reconnect-ui.show-message .reconnect-message {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

/* RTL support */
[dir="rtl"] .reconnect-message {
    direction: rtl;
}

/* ===== WiFi Icon with Animation ===== */
.reconnect-icon {
    width: 32px;
    height: 32px;
    flex-shrink: 0;
    position: relative;
}

.reconnect-icon svg {
    width: 100%;
    height: 100%;
}

/* Spinning loader */
.reconnect-spinner {
    color: hsl(var(--primary));
}

/* Animate wifi signal waves */
.reconnect-spinner path:nth-child(1) {
    animation: reconnect-wave 1.5s ease-in-out infinite;
    animation-delay: 0.3s;
}

.reconnect-spinner path:nth-child(2) {
    animation: reconnect-wave 1.5s ease-in-out infinite;
    animation-delay: 0.15s;
}

.reconnect-spinner path:nth-child(3) {
    animation: reconnect-wave 1.5s ease-in-out infinite;
    animation-delay: 0s;
}

/* Warning state - pulsing icon */
#reconnect-ui.show-message .reconnect-spinner {
    color: hsl(var(--warning));
}

#reconnect-ui.show-message .reconnect-spinner path,
#reconnect-ui.show-message .reconnect-spinner circle {
    animation: reconnect-pulse-icon 2s ease-in-out infinite;
}

/* Failed state - red icon */
#reconnect-ui.failed .reconnect-spinner {
    color: hsl(var(--destructive));
}

#reconnect-ui.failed .reconnect-spinner path,
#reconnect-ui.failed .reconnect-spinner circle {
    animation: reconnect-shake 0.5s ease-in-out;
}

/* ===== Text Content ===== */
.reconnect-text {
    font-size: 0.925rem;
    color: hsl(var(--foreground));
    line-height: 1.5;
}

.reconnect-text strong {
    font-weight: 600;
    display: block;
    margin-bottom: 3px;
    font-size: 0.95rem;
}

.reconnect-text span {
    font-size: 0.85rem;
    color: hsl(var(--muted-foreground));
    display: block;
}

/* ===== Close Button ===== */
.reconnect-close {
    width: 32px;
    height: 32px;
    border-radius: 10px;
    border: none;
    background: hsl(var(--muted) / 0.8);
    color: hsl(var(--muted-foreground));
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    flex-shrink: 0;
    margin-inline-start: 4px;
}

.reconnect-close:hover {
    background: hsl(var(--muted));
    color: hsl(var(--foreground));
    transform: scale(1.05);
}

.reconnect-close:active {
    transform: scale(0.95);
}

.reconnect-close svg {
    width: 16px;
    height: 16px;
}

/* ===== Animations ===== */

/* Progress bar animation */
@keyframes reconnect-progress {
    0% {
        background-position: 100% 0;
    }
    100% {
        background-position: -100% 0;
    }
}

/* Shimmer overlay */
@keyframes reconnect-shimmer {
    0% {
        background-position: 200% 0;
    }
    100% {
        background-position: -200% 0;
    }
}

/* Pulse for failed state */
@keyframes reconnect-pulse-bar {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.6;
    }
}

/* Spinner rotation */
@keyframes reconnect-spin {
    from {
        transform: rotate(0deg);
    }
    to {
        transform: rotate(360deg);
    }
}

/* Icon pulse */
@keyframes reconnect-pulse-icon {
    0%, 100% {
        transform: scale(1);
        opacity: 1;
    }
    50% {
        transform: scale(1.1);
        opacity: 0.8;
    }
}

/* Shake for error */
@keyframes reconnect-shake {
    0%, 100% { transform: translateX(0); }
    10%, 30%, 50%, 70%, 90% { transform: translateX(-4px); }
    20%, 40%, 60%, 80% { transform: translateX(4px); }
}

/* WiFi wave animation */
@keyframes reconnect-wave {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.3;
    }
}

/* ===== Dark Mode Adjustments ===== */
.dark .reconnect-message {
    box-shadow: 
        0 4px 6px -1px rgba(0, 0, 0, 0.3),
        0 10px 20px -5px rgba(0, 0, 0, 0.4),
        0 0 0 1px rgba(255, 255, 255, 0.1);
}

/* ===== Responsive ===== */
@media (max-width: 480px) {
    .reconnect-message {
        left: 16px;
        right: 16px;
        transform: translateX(0) translateY(-120px);
        padding: 12px 16px;
        gap: 12px;
    }
    
    #reconnect-ui.show-message .reconnect-message {
        transform: translateX(0) translateY(0);
    }
    
    .reconnect-icon {
        width: 28px;
        height: 28px;
    }
    
    .reconnect-text {
        font-size: 0.875rem;
    }
    
    .reconnect-text strong {
        font-size: 0.9rem;
    }
    
    .reconnect-text span {
        font-size: 0.8rem;
    }
}
