:root { 
    --primary: #4f46e5;      /* Indigo principal */
    --primary-light: #818cf8; 
    --bg: #f8fafc;           /* Fundo da página */
    --card: #ffffff;         /* Fundo dos cartões */
    --text: #1e293b;         /* Texto escuro */
    --text-muted: #64748b;   /* Texto secundário */
    --border: #e2e8f0;       /* Bordas */
    --success: #10b981;      /* Verde */
    --danger: #ef4444;       /* Vermelho */
    --warning: #f59e0b;      /* Laranja */
}

* { box-sizing: border-box; }

body { 
    font-family: 'Segoe UI', Roboto, Helvetica, Arial, sans-serif; 
    background: var(--bg); 
    color: var(--text); 
    margin: 0; 
    height: 100vh; 
    overflow: hidden; /* Evita scroll na página inteira no desktop */
}

/* =========================================
   LAYOUT PRINCIPAL
   ========================================= */
.app-container { 
    display: flex; 
    height: 100%; 
    width: 100%; 
}

/* BARRA LATERAL */
.sidebar { 
    width: 420px; 
    background: var(--card); 
    border-right: 1px solid var(--border); 
    display: flex; 
    flex-direction: column; 
    z-index: 20;
    box-shadow: 4px 0 15px rgba(0,0,0,0.05);
}

.header-mobile { 
    display: flex; 
    justify-content: space-between; 
    align-items: center; 
    padding: 1rem 1.5rem; 
    border-bottom: 1px solid transparent; /* Invisível no desktop */
}

#sidebarContent { 
    padding: 1.5rem; 
    overflow-y: auto; 
    flex: 1; 
    display: flex; 
    flex-direction: column; 
    gap: 1rem; 
}

/* =========================================
   RESPONSIVIDADE (MOBILE)
   ========================================= */
.mobile-only { display: none; background: none; border: none; font-size: 1.5rem; cursor: pointer; color: var(--text); }

@media (max-width: 768px) {
    .app-container { flex-direction: column; overflow-y: auto; }
    
    .sidebar { 
        width: 100%; 
        height: auto; 
        border-right: none; 
        border-bottom: 1px solid var(--border); 
        box-shadow: none;
    }
    
    .header-mobile { border-bottom: 1px solid var(--border); background: var(--card); }
    .mobile-only { display: block; }
    
    /* Menu esconde/mostra no mobile */
    #sidebarContent { display: none; padding: 1rem; border-top: 1px solid var(--border); }
    
    .visualization-area { 
        height: 60vh; 
        min-height: 400px; 
        border-top: 1px solid var(--border);
    }
    
    body { overflow: auto; } /* Libera scroll no mobile */
}

/* =========================================
   COMPONENTES UI
   ========================================= */
h1 { margin: 0; font-size: 1.3rem; color: var(--primary); font-weight: 700; }
.badge { padding: 3px 8px; border-radius: 12px; font-size: 0.7rem; vertical-align: middle; font-weight: 600; letter-spacing: 0.5px; }

/* Abas */
.tabs { display: flex; gap: 8px; margin-bottom: 5px; }
.tab-btn { 
    flex: 1; 
    padding: 10px; 
    border: 1px solid var(--border); 
    background: #f1f5f9; 
    color: var(--text-muted);
    cursor: pointer; 
    border-radius: 6px; 
    font-size: 0.85rem; 
    font-weight: 600;
    transition: all 0.2s;
}
.tab-btn.active { 
    background: var(--primary); 
    color: white; 
    border-color: var(--primary); 
}

/* Caixas de Input */
.protocol-box { 
    background: #f8fafc; 
    border: 1px solid var(--border); 
    padding: 12px; 
    border-radius: 8px; 
}
.input-label { 
    font-weight: 700; 
    font-size: 0.7rem; 
    color: var(--text-muted); 
    display: block; 
    margin-bottom: 6px; 
    text-transform: uppercase; 
    letter-spacing: 0.5px;
}
.std-select, input[type="number"], input[type="password"] { 
    width: 100%; 
    padding: 8px; 
    border: 1px solid #cbd5e1; 
    border-radius: 6px; 
    font-size: 0.9rem; 
    background: #fff;
}

/* Área de Upload e Texto */
.file-drop-area { 
    border: 2px dashed #cbd5e1; 
    padding: 20px; 
    text-align: center; 
    border-radius: 8px; 
    cursor: pointer; 
    position: relative; 
    background: #fafafa; 
    transition: all 0.2s;
}
.file-drop-area:hover { border-color: var(--primary); background: #eef2ff; }
.file-input { position: absolute; top:0; left:0; width:100%; height:100%; opacity:0; cursor: pointer; }

#manualText { 
    width: 100%; 
    height: 120px; 
    padding: 10px; 
    border: 1px solid #cbd5e1; 
    border-radius: 6px; 
    resize: vertical; 
    font-family: inherit; 
    font-size: 0.9rem; 
    margin-top: 10px; 
    line-height: 1.5;
}

/* =========================================
   BOTÕES E FEEDBACK (LOADING)
   ========================================= */
button.action-btn { 
    padding: 12px; 
    background: var(--primary); 
    color: white; 
    border: none; 
    border-radius: 6px; 
    font-weight: 700; 
    cursor: pointer; 
    width: 100%; 
    margin-top: 15px; 
    font-size: 0.9rem;
    box-shadow: 0 2px 5px rgba(79, 70, 229, 0.2);
    transition: background 0.2s;
}
button.action-btn:hover { background: #4338ca; }
button.action-btn:disabled { background: #cbd5e1; cursor: not-allowed; box-shadow: none; }

/* Animação de Loading no Botão */
button.action-btn.loading {
    background: #94a3b8;
    cursor: wait;
    position: relative;
    padding-left: 40px; /* Espaço para o spinner */
}
button.action-btn.loading::after {
    content: "";
    position: absolute;
    left: 20px; top: 50%; 
    transform: translateY(-50%);
    width: 16px; height: 16px;
    border: 2px solid #fff;
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: translateY(-50%) rotate(360deg); } }

button.secondary-btn { 
    padding: 8px; 
    background: #fff; 
    border: 1px solid #e2e8f0; 
    color: var(--text-muted);
    border-radius: 6px; 
    width: 100%; 
    margin-top: 10px; 
    cursor: pointer; 
    font-size: 0.8rem; 
}
button.secondary-btn:hover { border-color: var(--primary); color: var(--primary); }

/* =========================================
   STATUS BOX & PIPELINE (NOVO v12)
   ========================================= */
#aiStatus {
    background: #fff;
    border: 1px solid var(--border);
    padding: 12px;
    border-radius: 8px;
    margin-top: 15px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
}

.status-header {
    display: flex; justify-content: space-between;
    font-size: 0.75rem; font-weight: 700; color: #475569; margin-bottom: 8px;
}

.progress-bar {
    background: #f1f5f9; height: 6px; border-radius: 3px; overflow: hidden; margin-bottom: 8px;
}
.progress-fill {
    height: 100%; background: linear-gradient(90deg, var(--primary), var(--primary-light)); width: 0%; transition: width 0.4s ease;
}

.pipeline-steps { display: flex; gap: 6px; margin-top: 4px; }
.step {
    flex: 1; height: 4px; background: #e2e8f0; border-radius: 2px; transition: all 0.3s ease;
}
.step.active { background: var(--primary); box-shadow: 0 0 8px rgba(79, 70, 229, 0.4); }
.step.done { background: var(--success); }
.step.error { background: var(--danger); }

.step-label {
    text-align: center; font-size: 0.65rem; color: #94a3b8; margin-top: 4px; text-transform: uppercase;
}
.step.active + .step-label { color: var(--primary); font-weight: bold; }
.step.done + .step-label { color: var(--success); }

/* =========================================
   MÉTRICAS & RESULTADOS
   ========================================= */
.metrics-grid { 
    display: grid; 
    /* Layout flexível para 2 colunas */
    grid-template-columns: repeat(2, 1fr); 
    gap: 10px; 
    margin-top: 1.5rem; 
}
.metric-card { 
    background: #f8fafc; 
    padding: 12px; 
    border-radius: 8px; 
    text-align: center; 
    border: 1px solid var(--border);
}
.metric-val { font-size: 1.2rem; font-weight: 800; display: block; color: var(--text); }
.metric-label { font-size: 0.65rem; color: var(--text-muted); text-transform: uppercase; margin-top: 2px; }

.alert-box { 
    padding: 15px; 
    border-radius: 8px; 
    font-size: 0.85rem; 
    margin-top: 15px; 
    display: none; 
    line-height: 1.5; 
    border-left: 4px solid transparent;
}
.alert-safe { background: #ecfdf5; color: #065f46; border-left-color: #10b981; }
.alert-danger { background: #fef2f2; color: #991b1b; border-left-color: #ef4444; }
.alert-warning { background: #fffbeb; color: #92400e; border-left-color: #f59e0b; }

/* Histórico */
.history-list { max-height: 300px; overflow-y: auto; margin-top: 10px; }

/* =========================================
   ÁREA DE VISUALIZAÇÃO
   ========================================= */
.visualization-area { 
    flex: 1; 
    background: #f1f5f9; /* Fundo cinza claro para ajudar na depuração visual */
    position: relative; 
    display: flex; 
    flex-direction: column; 
    min-height: 0; 
}

#network { 
    flex: 1; 
    width: 100%; 
    height: 100%;
    min-height: 400px; /* Garante que o grafo não suma */
    background: #ffffff; 
}

.timeline-container { 
    height: 100px; 
    background: rgba(255,255,255,0.95); 
    border-top: 1px solid var(--border); 
    padding: 10px 20px; 
    width: 100%; 
}

.legend-box { 
    position: absolute; 
    bottom: 120px; 
    right: 20px; 
    background: rgba(255,255,255,0.95); 
    padding: 12px; 
    border-radius: 8px; 
    font-size: 0.75rem; 
    border: 1px solid var(--border); 
    pointer-events: none; 
    box-shadow: 0 2px 10px rgba(0,0,0,0.05);
}
.legend-item { margin-bottom: 5px; display: flex; align-items: center; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; margin-right: 8px; }
.red-rect { width: 14px; height: 5px; background: var(--danger); display: inline-block; margin-right: 8px; border-radius: 2px; }
.blue { background: var(--primary); }
.grey { background: #94a3b8; }
