/**
 * SIGRAWEB PREMIUM LOADING
 * Sistema de carregamento elegante com progresso em tempo real
 */

/* ============================================
   OVERLAY DE CARREGAMENTO
   ============================================ */

#sigraweb-loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(8px);
    z-index: 999999;
    display: none;
    align-items: center;
    justify-content: center;
    animation: fadeIn 300ms ease-in-out;
}

#sigraweb-loading-overlay.active {
    display: flex;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

/* ============================================
   CARD DE CARREGAMENTO
   ============================================ */

.sigraweb-loading-card {
    background: #ffffff;
    border-radius: 20px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3),
                0 10px 30px rgba(0, 0, 0, 0.2);
    padding: 40px;
    max-width: 500px;
    width: calc(100vw - 40px);
    max-height: calc(100vh - 80px); /* Limita altura máxima */
    overflow-y: auto; /* Adiciona scroll vertical quando necessário */
    overflow-x: hidden; /* Esconde scroll horizontal */
    text-align: center;
    animation: slideIn 400ms cubic-bezier(0.16, 1, 0.3, 1);
}

/* Estilização da scrollbar */
.sigraweb-loading-card::-webkit-scrollbar {
    width: 8px;
}

.sigraweb-loading-card::-webkit-scrollbar-track {
    background: #f5f5f7;
    border-radius: 10px;
}

.sigraweb-loading-card::-webkit-scrollbar-thumb {
    background: #c7c7cc;
    border-radius: 10px;
    transition: background 200ms ease;
}

.sigraweb-loading-card::-webkit-scrollbar-thumb:hover {
    background: #aeaeb2;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(-20px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* ============================================
   ÍCONE ANIMADO
   ============================================ */

.sigraweb-loading-icon {
    width: 60px;
    height: 60px;
    margin: 0 auto 24px;
    position: relative;
}

.sigraweb-loading-spinner {
    width: 60px;
    height: 60px;
    border: 4px solid rgba(0, 122, 255, 0.1);
    border-top-color: #007AFF;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

/* ============================================
   TÍTULO E MENSAGEM
   ============================================ */

.sigraweb-loading-title {
    font-size: 20px;
    font-weight: 600;
    color: #1d1d1f;
    margin-bottom: 12px;
    letter-spacing: -0.3px;
}

.sigraweb-loading-message {
    font-size: 15px;
    color: #515154;
    margin-bottom: 24px;
    line-height: 1.5;
}

/* ============================================
   LISTA DE PROGRESSO
   ============================================ */

.sigraweb-loading-progress {
    margin-top: 24px;
    text-align: left;
}

.sigraweb-loading-step {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    margin-bottom: 8px;
    background: #f5f5f7;
    border-radius: 12px;
    transition: all 200ms ease;
}

.sigraweb-loading-step.active {
    background: rgba(0, 122, 255, 0.08);
    border-left: 4px solid #007AFF;
    padding-left: 12px;
}

.sigraweb-loading-step.completed {
    background: rgba(52, 199, 89, 0.08);
    border-left: 4px solid #34C759;
    padding-left: 12px;
}

.sigraweb-loading-step-icon {
    width: 24px;
    height: 24px;
    margin-right: 12px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.sigraweb-loading-step-icon i {
    font-size: 16px;
    color: #86868b;
}

.sigraweb-loading-step.active .sigraweb-loading-step-icon i {
    color: #007AFF;
}

.sigraweb-loading-step.completed .sigraweb-loading-step-icon i {
    color: #34C759;
}

.sigraweb-loading-step-content {
    flex: 1;
}

.sigraweb-loading-step-label {
    font-size: 14px;
    font-weight: 500;
    color: #1d1d1f;
    margin-bottom: 4px;
}

.sigraweb-loading-step-detail {
    font-size: 13px;
    color: #86868b;
    font-family: 'SF Mono', 'Monaco', 'Courier New', monospace;
}

.sigraweb-loading-step.active .sigraweb-loading-step-detail {
    color: #007AFF;
}

.sigraweb-loading-step.completed .sigraweb-loading-step-detail {
    color: #34C759;
}

/* Spinner pequeno para etapa ativa */
.sigraweb-loading-step.active .sigraweb-loading-step-icon::before {
    content: '';
    position: absolute;
    width: 24px;
    height: 24px;
    border: 2px solid rgba(0, 122, 255, 0.2);
    border-top-color: #007AFF;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

/* ============================================
   BARRA DE PROGRESSO GLOBAL
   ============================================ */

.sigraweb-loading-progress-bar {
    width: 100%;
    height: 6px;
    background: #f5f5f7;
    border-radius: 3px;
    overflow: hidden;
    margin-top: 24px;
}

.sigraweb-loading-progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #007AFF 0%, #0066E6 100%);
    border-radius: 3px;
    transition: width 300ms cubic-bezier(0.4, 0, 0.2, 1);
    width: 0%;
}

.sigraweb-loading-progress-text {
    font-size: 13px;
    color: #86868b;
    margin-top: 8px;
    text-align: center;
}

/* ============================================
   RESPONSIVIDADE
   ============================================ */

@media (max-width: 768px) {
    .sigraweb-loading-card {
        padding: 32px 24px;
        border-radius: 16px;
    }

    .sigraweb-loading-title {
        font-size: 18px;
    }

    .sigraweb-loading-message {
        font-size: 14px;
    }

    .sigraweb-loading-step {
        padding: 10px 12px;
    }

    .sigraweb-loading-step-label {
        font-size: 13px;
    }

    .sigraweb-loading-step-detail {
        font-size: 12px;
    }
}

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

@media (prefers-color-scheme: dark) {
    .sigraweb-loading-card {
        background: #1c1c1e;
    }

    .sigraweb-loading-title {
        color: #f5f5f7;
    }

    .sigraweb-loading-message {
        color: #d1d1d6;
    }

    .sigraweb-loading-step {
        background: #2c2c2e;
    }

    .sigraweb-loading-step.active {
        background: rgba(0, 122, 255, 0.15);
    }

    .sigraweb-loading-step.completed {
        background: rgba(52, 199, 89, 0.15);
    }

    .sigraweb-loading-step-label {
        color: #f5f5f7;
    }

    .sigraweb-loading-progress-bar {
        background: #2c2c2e;
    }
}

/* ============================================
   ANIMAÇÃO DE PULSO (para números que mudam)
   ============================================ */

@keyframes pulse {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.05);
    }
}

.sigraweb-loading-step-detail.updating {
    animation: pulse 300ms ease-in-out;
}

/* ============================================
   CONTEÚDO CUSTOMIZADO (CAPTCHA, etc)
   ============================================ */

.sigraweb-loading-custom-container {
    margin: 20px 0;
}

.sigraweb-loading-custom-content {
    margin-bottom: 16px;
}

/* Estilo específico para o captcha dentro do loading */
.sigraweb-loading-custom-content iframe {
    max-width: 100%;
}

@media (max-width: 768px) {
    .sigraweb-loading-custom-container {
        margin: 16px 0;
    }
}

/* ============================================
   LOGS DOS STEPS
   ============================================ */

.sigraweb-loading-step-logs {
    display: none;
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.sigraweb-loading-step-log-entry {
    font-size: 12px;
    padding: 4px 0;
    display: flex;
    align-items: flex-start;
    gap: 8px;
    line-height: 1.4;
}

.sigraweb-loading-step-log-entry i {
    flex-shrink: 0;
    margin-top: 2px;
}

.sigraweb-loading-step-log-text {
    color: #ffffff;
    font-weight: 400;
}

/* Cores dos ícones por tipo de log */
.sigraweb-loading-step-log-info i {
    color: #5ac8fa;
}

.sigraweb-loading-step-log-success i {
    color: #34C759;
}

.sigraweb-loading-step-log-warning i {
    color: #ffcc00;
}

.sigraweb-loading-step-log-error i {
    color: #ff3b30;
}

/* Dark Mode para logs */
@media (prefers-color-scheme: dark) {
    .sigraweb-loading-step-logs {
        border-top-color: rgba(255, 255, 255, 0.15);
    }

    .sigraweb-loading-step-log-text {
        color: #f5f5f7;
    }
}
